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

Enhanced Error Handling in AssetViewSet #1737

Merged
merged 4 commits into from
Jan 9, 2024
Merged

Conversation

Ashesh3
Copy link
Member

@Ashesh3 Ashesh3 commented Dec 3, 2023

Proposed Changes

In this commit, two key changes were made to the operate_assets function within viewsets/asset.py. The modifications enhance error reporting and provide clearer error messages for the user.

  1. Detailed Validation Error Message:
    In case of a ValidationError, the key 'message' in the response dictionary was renamed to 'detail', ensuring consistent terminology across all responses.

  2. Improved APIException Handling:
    The previous implemention simply returned the exception's detail and status_code. Now, it's refactored to a more informative error message when communication with the middleware fails. A new status (HTTP_424_FAILED_DEPENDENCY) is returned to signify that the failure is due to an unmet dependency, providing better context on the nature of the error.

image

  if (error.response.status > 400 && error.response.status < 500) {
        .....
              Notification.Error({
                msg: error.response.data.detail,
              });

The frontend expects the error to be sent in detail key for 4xx errors.
https://github.com/coronasafe/care_fe/blob/develop/src/Redux/fireRequest.tsx#L152-L164

@coronasafe/care-backend-maintainers @coronasafe/care-backend-admins

Copy link

codecov bot commented Dec 3, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (ef73d93) 61.04% compared to head (0554d0b) 61.04%.

Files Patch % Lines
care/facility/api/viewsets/asset.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1737   +/-   ##
=======================================
  Coverage   61.04%   61.04%           
=======================================
  Files         208      208           
  Lines       11526    11526           
  Branches     1656     1656           
=======================================
  Hits         7036     7036           
  Misses       4218     4218           
  Partials      272      272           

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

@Ashesh3 Ashesh3 requested a review from sainak December 27, 2023 08:16
@Ashesh3
Copy link
Member Author

Ashesh3 commented Dec 28, 2023

@rithviknishad @vigneshhari could you review this?

@vigneshhari vigneshhari merged commit 50924ae into master Jan 9, 2024
10 of 11 checks passed
@vigneshhari vigneshhari deleted the operate-asset-error branch January 9, 2024 18:14
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.

None yet

5 participants