From 3ffef34690ddc3c96b871c38a2b3502d4f024dad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Mon, 14 Feb 2022 16:53:40 +0100 Subject: [PATCH] Allow `sendAPIError()` to be used like `fmt.Sprintf` --- internal/manager/api_impl/api_impl.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/manager/api_impl/api_impl.go b/internal/manager/api_impl/api_impl.go index 28f36cf0..d1925449 100644 --- a/internal/manager/api_impl/api_impl.go +++ b/internal/manager/api_impl/api_impl.go @@ -23,6 +23,7 @@ package api_impl import ( "context" + "fmt" "github.com/labstack/echo/v4" "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 // 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{ Code: int32(code), Message: message,