Skip to content

Conversation

@JeethJJ
Copy link
Contributor

@JeethJJ JeethJJ commented Dec 3, 2025

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

Copilot AI review requested due to automatic review settings December 3, 2025 08:39
Copilot finished reviewing on behalf of JeethJJ December 3, 2025 08:42
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 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 WriteSuccessResponse and WriteErrorResponse utilities across all handlers
  • Removed redundant helper functions like buildUserSchemaResponse, writeToResponse, and handleEncodingError from individual packages
  • Updated test expectations to check for the standard encoding error message from the utility functions
  • Removed unused encoding/json imports 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
Copy link

codecov bot commented Dec 3, 2025

Codecov Report

❌ Patch coverage is 80.11696% with 34 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.62%. Comparing base (b406864) to head (2b862f3).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
backend/internal/user/handler.go 30.76% 27 Missing ⚠️
backend/internal/system/export/handler.go 50.00% 5 Missing ⚠️
backend/internal/flow/flowexec/handler.go 80.00% 1 Missing ⚠️
backend/internal/userschema/handler.go 88.88% 1 Missing ⚠️
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     
Flag Coverage Δ
backend-integration-postgres 59.00% <56.72%> (+0.08%) ⬆️
backend-integration-sqlite 58.96% <56.72%> (+0.08%) ⬆️
backend-unit 73.59% <68.42%> (+0.32%) ⬆️
frontend-apps-develop-unit 88.45% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JeethJJ JeethJJ force-pushed the refactor/cleanup-api-handler-response-utils branch from adef928 to 2b862f3 Compare December 3, 2025 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant