Skip to content

Commit

Permalink
Fix error handler for required query parameters (#857)
Browse files Browse the repository at this point in the history
  • Loading branch information
abdollahpour committed Nov 21, 2022
1 parent 050c4bf commit 0138e13
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions pkg/codegen/templates/gin/gin-wrappers.tmpl
Expand Up @@ -62,16 +62,15 @@ func (siw *ServerInterfaceWrapper) {{$opid}}(c *gin.Context) {
var value {{.TypeDef}}
err = json.Unmarshal([]byte(paramValue), &value)
if err != nil {
siw.ErrorHandler(c, fmt.Errorf("Error unmarshalling parameter '{{.ParamName}}' as JSON: %s", err), http.StatusBadRequest) {
siw.ErrorHandler(c, fmt.Errorf("Error unmarshalling parameter '{{.ParamName}}' as JSON: %s", err), http.StatusBadRequest)
return
}

params.{{.GoName}} = {{if not .Required}}&{{end}}value
{{end}}
}{{if .Required}} else {
if !siw.ErrorHandler(c, fmt.Errorf("Query argument {{.ParamName}} is required, but not found: %s", err), http.StatusBadRequest) {
return
}
siw.ErrorHandler(c, fmt.Errorf("Query argument {{.ParamName}} is required, but not found: %s", err), http.StatusBadRequest)
return
}{{end}}
{{end}}

Expand Down

0 comments on commit 0138e13

Please sign in to comment.