Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strictgin error handler #1600

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

actatum
Copy link

@actatum actatum commented May 6, 2024

Strict gin server doesn't currently use an error handler function. This adds the error handler to the strict gin handler

@@ -34,19 +47,18 @@ type strictHandler struct {
{{if .IsJSON }}
var body {{$opid}}{{.NameTag}}RequestBody
if err := ctx.ShouldBindJSON(&body); err != nil {
ctx.Status(http.StatusBadRequest)
ctx.Error(err)
sh.options.ErrorHandlerFunc(ctx, err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this not still be sending a http.StatusBadRequest?

return
} else if boundary := params["boundary"]; boundary == "" {
ctx.Error(http.ErrMissingBoundary)
sh.options.ErrorHandlerFunc(ctx, err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this not still be sending a http.ErrMissingBoundary?

@@ -93,14 +105,13 @@ type strictHandler struct {
response, err := handler(ctx, request)

if err != nil {
ctx.Error(err)
ctx.Status(http.StatusInternalServerError)
sh.options.ErrorHandlerFunc(ctx, err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this not still be sending a http.StatusInternalServerError?

}
} else if response != nil {
ctx.Error(fmt.Errorf("unexpected response type: %T", response))
sh.options.ErrorHandlerFunc(ctx, err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sh.options.ErrorHandlerFunc(ctx, err)
sh.options.ErrorHandlerFunc(ctx, fmt.Errorf("unexpected response type: %T", response))

@jamietanna jamietanna modified the milestones: v2.2.0, v2.3.0 Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants