-
Notifications
You must be signed in to change notification settings - Fork 241
Comprehensive cleanup to use WriteSuccessResponse and WriteErrorResponse #878
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: main
Are you sure you want to change the base?
Comprehensive cleanup to use WriteSuccessResponse and WriteErrorResponse #878
Conversation
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 comprehensively refactors HTTP response handling across the backend to use the newly introduced WriteSuccessResponse and WriteErrorResponse utility methods from internal/system/utils. The changes eliminate code duplication, ensure consistent error handling and logging, and improve maintainability by centralizing JSON encoding logic.
Key Changes:
- Replaced manual JSON encoding and header setting with
WriteSuccessResponseandWriteErrorResponseutilities across all handlers - Removed redundant helper functions like
buildUserSchemaResponse,writeToResponse, andhandleEncodingErrorfrom individual packages - Updated test expectations to check for the standard encoding error message from the utility functions
- Removed unused
encoding/jsonimports where no longer needed
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| backend/internal/userschema/handler.go | Replaced manual JSON encoding with utility methods; removed buildUserSchemaResponse helper |
| backend/internal/user/handler.go | Converted all HTTP responses to use utility methods; improved error response consistency |
| backend/internal/system/healthcheck/handler/healthcheckhandler.go | Updated to use WriteSuccessResponse with conditional status codes |
| backend/internal/system/export/handler.go | Migrated to utility methods; contains minor formatting issue on line 54 |
| backend/internal/role/handler.go | Removed writeToResponse and handleEncodingError helpers; migrated to utility methods |
| backend/internal/role/handler_test.go | Removed obsolete tests for deleted helper functions |
| backend/internal/oauth/oauth2/userinfo/handler.go | Simplified response handling while preserving OAuth2-specific headers |
| backend/internal/oauth/oauth2/token/token_handler.go | Cleaned up import organization and migrated to utility methods |
| backend/internal/oauth/oauth2/introspect/handler.go | Only success responses migrated; error responses use OAuth2-specific format |
| backend/internal/oauth/oauth2/discovery/handler.go | Added debug logging and migrated to utility methods |
| backend/internal/oauth/oauth2/dcr/handler.go | Removed unused logger variable; migrated to utility methods |
| backend/internal/oauth/oauth2/authz/handler.go | Fixed duplicate import; migrated to utility methods |
| backend/internal/oauth/jwks/handler.go | Migrated to utility methods for both success and error responses |
| backend/internal/notification/message_handler.go | Comprehensive migration to utility methods across all handlers |
| backend/internal/idp/handler.go | Migrated all CRUD operations to use utility methods |
| backend/internal/group/handler.go | Migrated to utility methods across all handlers |
| backend/internal/group/handler_test.go | Updated test expectations for encoding error messages |
| backend/internal/flow/flowexec/handler.go | Migrated to utility methods with improved status code handling |
| backend/internal/branding/handler.go | Removed helper functions; migrated to utility methods |
| backend/internal/branding/handler_test.go | Removed tests for deleted helper functions |
| backend/internal/authn/handler.go | Removed custom response helper methods; migrated to utility methods |
| backend/internal/application/handler.go | Comprehensive migration to utility methods across all handlers |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #878 +/- ##
==========================================
+ Coverage 87.22% 87.62% +0.39%
==========================================
Files 302 310 +8
Lines 24017 23852 -165
Branches 606 606
==========================================
- Hits 20949 20900 -49
+ Misses 1886 1825 -61
+ Partials 1182 1127 -55
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…ErrorResponse utilities
adef928 to
2b862f3
Compare
With [1] we have introduced WriteSuccessResponse and WriteErrorResponse helper methods. In this PR we are modifying all the places with references to use this newly introduced until methods.
[1] #845
Related Issues