-
Notifications
You must be signed in to change notification settings - Fork 0
Add custom err handler #207
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,7 +30,7 @@ func SetupRouting(r gin.IRouter, s *Server) { | |
|
|
||
| resolve.Use(validDomain, validName) | ||
|
|
||
| resolve.GET("/:domain/:name", s.Resolve) | ||
| resolve.GET("/:domain/:name", AsErrHandler(s.Resolve)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Approve and Recommend Expanding Error Handling Consistency The modification to wrap Recommendations:
🔗 Analysis chainApprove change and suggest consistent application The modification to wrap Consider the following recommendations:
To ensure the change doesn't introduce unexpected behavior, please verify the following:
You can use the following script to check the This will help ensure that the error handling is implemented correctly and used consistently. 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Check AsErrHandler implementation and usage
# Check AsErrHandler implementation
echo "AsErrHandler implementation:"
rg -A 10 "func AsErrHandler" api/err.go
# Check AsErrHandler usage across the codebase
echo "\nAsErrHandler usage:"
rg "AsErrHandler\(" api/
Length of output: 500 |
||
| } | ||
|
|
||
| // Admin endpoints | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider the implications of removing
respondWithErrorBy directly returning the error instead of calling
respondWithError, we're no longer immediately responding to the client with an error status. This might lead to inconsistent error responses if not handled properly by the caller.Consider one of the following options:
respondWithErrorcall before returning the error.AsErrHandlerwrapper) properly handles all error cases and responds to the client appropriately.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Propose an alteration to AsErrHandler which makes use of a customer error type containing the error message and status to respond with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fabiante
Certainly! Here's an updated version of
AsErrHandlerthat uses a custom error type containing the error message and status code:Then, in your handler functions like
Resolve, you can return an*HTTPErrorwith the desired status code and error:This approach allows
AsErrHandlerto respond with the appropriate HTTP status codes based on the custom error returned by your handlers, ensuring consistent and flexible error handling.✏️ Learnings added