Allow sendAPIError() to be used like fmt.Sprintf

This commit is contained in:
Sybren A. Stüvel 2022-02-14 16:53:40 +01:00
parent eea219c3e2
commit 3ffef34690

View File

@ -23,6 +23,7 @@ package api_impl
import ( import (
"context" "context"
"fmt"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"gitlab.com/blender/flamenco-ng-poc/internal/manager/job_compilers" "gitlab.com/blender/flamenco-ng-poc/internal/manager/job_compilers"
@ -65,7 +66,12 @@ func NewFlamenco(jc JobCompiler, jps PersistenceService) *Flamenco {
// sendPetstoreError wraps sending of an error in the Error format, and // sendPetstoreError wraps sending of an error in the Error format, and
// handling the failure to marshal that. // handling the failure to marshal that.
func sendAPIError(e echo.Context, code int, message string) error { func sendAPIError(e echo.Context, code int, message string, args ...interface{}) error {
if len(args) > 0 {
// Only interpret 'message' as format string if there are actually format parameters.
message = fmt.Sprintf(message, args)
}
petErr := api.Error{ petErr := api.Error{
Code: int32(code), Code: int32(code),
Message: message, Message: message,