-
Notifications
You must be signed in to change notification settings - Fork 6
feat: improve error handling with custom error template #47
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
Conversation
- Add custom error template for better user experience - Replace c.Error() calls with proper error rendering - Add error handling for session.Save() operations - Remove default session options from main.go
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.
Pull Request Overview
This PR enhances error handling in the authentication system by introducing a custom error template and implementing proper error handling practices. The changes improve user experience by replacing generic HTTP error responses with user-friendly error pages and ensure session operations are properly error-checked.
- Added a custom HTML error template with modern styling for better user experience
- Replaced generic
c.Error()calls with proper error rendering using a newrenderError()method - Added comprehensive error handling for session save operations to prevent silent failures
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/mcp-proxy/main.go | Removed default session configuration options for cleaner setup |
| pkg/auth/templates/error.html | Added new custom error template with modern styling and error message display |
| pkg/auth/auth.go | Implemented renderError method, added error template parsing, and enhanced session save error handling |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| c.Header("Content-Type", "text/html; charset=utf-8") | ||
| c.Status(http.StatusInternalServerError) | ||
| if templateErr := a.errorTemplate.Execute(c.Writer, data); templateErr != nil { | ||
| c.AbortWithError(http.StatusInternalServerError, templateErr) |
Copilot
AI
Aug 20, 2025
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.
Using c.AbortWithError() after already setting the status and writing to the response can cause issues. Since the template execution failed, the response may be partially written. Consider using c.String(http.StatusInternalServerError, "Internal Server Error") instead to ensure a clean error response.
| c.AbortWithError(http.StatusInternalServerError, templateErr) | |
| c.String(http.StatusInternalServerError, "Internal Server Error") |
| c.AbortWithError(http.StatusInternalServerError, templateErr) | ||
| return | ||
| } | ||
| c.Abort() |
Copilot
AI
Aug 20, 2025
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.
The c.Abort() call is unnecessary here since the response has already been completed. The function should return after successfully executing the template. This call could interfere with the response that was just sent.
| c.Abort() |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Summary
This PR improves error handling throughout the authentication system by implementing a custom error template and better error handling practices.
Type of Change
Changes Made
pkg/auth/templates/error.html) for better user experiencec.Error()calls with proper error rendering usingrenderError()methodsession.Save()operations to prevent silent failuresBenefits