From d396a12d687d6918a7b609920382e54b3aa8cf5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Fri, 9 Jun 2023 20:14:30 +0200 Subject: [PATCH] fix missing error on missing json header --- scnserver/logic/application.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/scnserver/logic/application.go b/scnserver/logic/application.go index ab6026a..b64f344 100644 --- a/scnserver/logic/application.go +++ b/scnserver/logic/application.go @@ -239,15 +239,23 @@ func (app *Application) StartRequest(g *gin.Context, uri any, query any, body an } } - if body != nil && g.ContentType() == "application/json" { - if err := g.ShouldBindJSON(body); err != nil { - return nil, langext.Ptr(ginresp.APIError(g, 400, apierr.BINDFAIL_BODY_PARAM, "Failed to read body", err)) + if body != nil { + if g.ContentType() == "application/json" { + if err := g.ShouldBindJSON(body); err != nil { + return nil, langext.Ptr(ginresp.APIError(g, apierr.BindFailJSON, "Failed to read body", err)) + } + } else { + return nil, langext.Ptr(ginresp.APIError(g, apierr.BindFailJSON, "missing JSON body", nil)) } } - if form != nil && g.ContentType() == "multipart/form-data" { - if err := g.ShouldBindWith(form, binding.Form); err != nil { - return nil, langext.Ptr(ginresp.APIError(g, 400, apierr.BINDFAIL_BODY_PARAM, "Failed to read multipart-form", err)) + if form != nil { + if g.ContentType() == "multipart/form-data" { + if err := g.ShouldBindWith(form, binding.Form); err != nil { + return nil, langext.Ptr(ginresp.APIError(g, apierr.BindFailFormData, "Failed to read multipart-form", err)) + } + } else { + return nil, langext.Ptr(ginresp.APIError(g, apierr.BindFailJSON, "missing form body", nil)) } }