Skip to content
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

Return client error responses as structured JSON in the User Sharing API #823

Merged
merged 5 commits into from
Jan 30, 2025

Conversation

BimsaraBodaragama
Copy link
Member

@BimsaraBodaragama BimsaraBodaragama commented Jan 29, 2025

This PR updates the User Sharing API to return client error responses in a structured JSON format instead of plain text, ensuring consistency with other API responses. Additionally, it refactors the error handling logic by moving it from UsersApiServiceImpl to UsersApiServiceCore, improving maintainability and reducing redundant code.

Purpose

  • Standardize error responses across the API.
  • Improve error debugging and traceability by including traceId, errorCode, message, and description in the response.
  • Enhance code maintainability by centralizing error-handling logic.

Goals

  • Ensure all client error responses follow a structured JSON format.
  • Enhance the developer experience by making error responses more informative.
  • Reduce code duplication and improve maintainability by restructuring error handling.

Approach

  • Replaced plain text error responses with a structured JSON format.
  • Introduced the Error model to encapsulate error details.
  • Introduced the buildErrorResponse method to generate JSON responses containing:
    • traceId: Unique identifier for debugging.
    • errorCode: Specific error code for identification.
    • message: Short summary of the error.
    • description: Detailed explanation of the error.
  • Moved error handling logic from UsersApiServiceImpl to UsersApiServiceCore to improve modularity.
  • Refactored UsersApiServiceCore by introducing private methods to eliminate redundant code and enhance readability.

Related Issue

product-is issue: Client error responses of user sharing API should be returned as JSON responses #22596

@BimsaraBodaragama BimsaraBodaragama self-assigned this Jan 29, 2025
Yasasr1
Yasasr1 previously approved these changes Jan 30, 2025
@jenkins-is-staging
Copy link

PR builder started
Link: https://github.com/wso2/product-is/actions/runs/13048121047

@jenkins-is-staging
Copy link

PR builder completed
Link: https://github.com/wso2/product-is/actions/runs/13048121047
Status: success

Copy link

@jenkins-is-staging jenkins-is-staging left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving the pull request based on the successful pr build https://github.com/wso2/product-is/actions/runs/13048121047

@jenkins-is-staging
Copy link

PR builder started
Link: https://github.com/wso2/product-is/actions/runs/13052855765

@jenkins-is-staging
Copy link

PR builder completed
Link: https://github.com/wso2/product-is/actions/runs/13052855765
Status: success

Copy link

@jenkins-is-staging jenkins-is-staging left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving the pull request based on the successful pr build https://github.com/wso2/product-is/actions/runs/13052855765

@Yasasr1 Yasasr1 merged commit 2e831d7 into wso2:master Jan 30, 2025
4 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.

4 participants