Skip to content

Conversation

@hrntknr
Copy link
Member

@hrntknr hrntknr commented Aug 20, 2025

Summary

This PR improves error handling throughout the authentication system by implementing a custom error template and better error handling practices.

Type of Change

  • feat: A new feature

Changes Made

  • Added custom error template (pkg/auth/templates/error.html) for better user experience
  • Replaced generic c.Error() calls with proper error rendering using renderError() method
  • Added proper error handling for session.Save() operations to prevent silent failures
  • Removed default session options from main.go for cleaner configuration

Benefits

  • Users now see user-friendly error pages instead of generic HTTP error responses
  • Better error tracking and handling throughout the authentication flow
  • Improved reliability with proper session save error handling

- 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
Copilot AI review requested due to automatic review settings August 20, 2025 14:19
Copy link
Contributor

Copilot AI left a 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 new renderError() 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)
Copy link

Copilot AI Aug 20, 2025

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.

Suggested change
c.AbortWithError(http.StatusInternalServerError, templateErr)
c.String(http.StatusInternalServerError, "Internal Server Error")

Copilot uses AI. Check for mistakes.
c.AbortWithError(http.StatusInternalServerError, templateErr)
return
}
c.Abort()
Copy link

Copilot AI Aug 20, 2025

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.

Suggested change
c.Abort()

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Aug 20, 2025

Codecov Report

❌ Patch coverage is 4.76190% with 40 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/auth/auth.go 4.76% 36 Missing and 4 partials ⚠️

📢 Thoughts on this report? Let us know!

@hrntknr hrntknr merged commit 2ff3804 into main Aug 20, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants