fix missing error on missing json header

This commit is contained in:
Mike Schwörer 2023-06-09 20:14:30 +02:00
parent 3888c91a6b
commit d396a12d68
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
1 changed files with 14 additions and 6 deletions

View File

@ -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))
}
}