Skip to content

Commit

Permalink
Enhanced Error Handling in AssetViewSet (#1737)
Browse files Browse the repository at this point in the history
* Fix error handling in AssetViewSet

* set HTTP_502_BAD_GATEWAY
  • Loading branch information
Ashesh3 authored Jan 9, 2024
1 parent 9f172fb commit 50924ae
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions care/facility/api/viewsets/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def operate_assets(self, request, *args, **kwargs):
return Response({"result": result}, status=status.HTTP_200_OK)

except ValidationError as e:
return Response({"message": e.detail}, status=status.HTTP_400_BAD_REQUEST)
return Response({"detail": e.detail}, status=status.HTTP_400_BAD_REQUEST)

except KeyError as e:
return Response(
Expand All @@ -347,7 +347,12 @@ def operate_assets(self, request, *args, **kwargs):
)

except APIException as e:
return Response(e.detail, e.status_code)
return Response(
{
"detail": f"Communication with the middleware failed.\nReceived status code: {e.status_code}"
},
status=status.HTTP_502_BAD_GATEWAY,
)

except Exception as e:
print(f"error: {e}")
Expand Down

0 comments on commit 50924ae

Please sign in to comment.