refactor: simplify error handling in oidc authorize handler#907
refactor: simplify error handling in oidc authorize handler#907steveiliop56 wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughThis PR refactors authorization error handling in the OIDC controller. A new ChangesOIDC Authorization Error Parameter Struct and Helper Refactoring
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/controller/oidc_controller.go (1)
551-551: ⚡ Quick winUse warn-level logs for expected authorization denials.
Logging every authorize failure as
Errorwill over-noise alerts for normal client/user mistakes (invalid_request, unauthenticated user, unknown client). Consider loggingWarnby default and reservingErrorfor actual server failures (e.g.,server_errorpaths).Proposed adjustment
func (controller *OIDCController) authorizeError(c *gin.Context, params authorizeErrorParams) { - controller.log.App.Error().Err(params.err).Str("reason", params.reason).Msg("Authorization error") + logEvent := controller.log.App.Warn() + if params.callbackError == "server_error" { + logEvent = controller.log.App.Error() + } + logEvent.Err(params.err).Str("reason", params.reason).Msg("Authorization error")🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/controller/oidc_controller.go` at line 551, The authorization failure is being logged at Error level unconditionally; update the log in oidc_controller.go that currently calls controller.log.App.Error().Err(params.err).Str("reason", params.reason).Msg("Authorization error") to use Warn() for expected client/user denials (e.g., invalid_request, unauthenticated, unknown_client) and only use Error() for genuine server-side failures (e.g., when params.reason == "server_error" or when params.err indicates an internal failure). Implement a small conditional around controller.log.App to call .Warn() by default and .Error() when the reason matches server error criteria, preserving Err(params.err), Str("reason", params.reason) and the same Msg("Authorization error").
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@internal/controller/oidc_controller.go`:
- Line 551: The authorization failure is being logged at Error level
unconditionally; update the log in oidc_controller.go that currently calls
controller.log.App.Error().Err(params.err).Str("reason",
params.reason).Msg("Authorization error") to use Warn() for expected client/user
denials (e.g., invalid_request, unauthenticated, unknown_client) and only use
Error() for genuine server-side failures (e.g., when params.reason ==
"server_error" or when params.err indicates an internal failure). Implement a
small conditional around controller.log.App to call .Warn() by default and
.Error() when the reason matches server error criteria, preserving
Err(params.err), Str("reason", params.reason) and the same Msg("Authorization
error").
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: adbea7db-1e49-442c-9e74-82a108d9b3d2
📒 Files selected for processing (1)
internal/controller/oidc_controller.go
Summary by CodeRabbit
Bug Fixes
Refactor