Skip to content

Commit

Permalink
exception handling for .save and .delete methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ManaliTanna committed Nov 6, 2023
1 parent 8ab904a commit a6ee018
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions furbaby/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,16 @@ def update_location_record(self, request):
},
status=status.HTTP_404_NOT_FOUND,
)
except Exception as e:
return json_response(
data={
"error": "something went wrong while updating the location record",
"error message": str(e),
"location id": location_id,
"user id": request.user.id,
},
status=status.HTTP_500_INTERNAL_SERVER_ERROR,
)

def delete_location_record(self, request):
try:
Expand All @@ -276,6 +286,16 @@ def delete_location_record(self, request):
},
status=status.HTTP_404_NOT_FOUND,
)
except Exception as e:
return json_response(
data={
"error": "something went wrong while deleting the location record",
"error message": str(e),
"location id": location_id,
"user id": request.user.id,
},
status=status.HTTP_500_INTERNAL_SERVER_ERROR,
)


@api_view(["GET", "POST", "OPTIONS", "PUT", "PATCH", "DELETE"])
Expand Down

0 comments on commit a6ee018

Please sign in to comment.