From 3afda844e7ed79b640cb61c263eae217edcaf002 Mon Sep 17 00:00:00 2001 From: Nassim Tabchiche Date: Mon, 12 Feb 2024 16:02:25 +0100 Subject: [PATCH] Fix error handling Returning exception content as Response data discloses stack trace information --- backend/library/views.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/library/views.py b/backend/library/views.py index 2f6fd80130..5d291553cd 100644 --- a/backend/library/views.py +++ b/backend/library/views.py @@ -62,10 +62,13 @@ def destroy(self, request, *args, pk, **kwargs): try: library.delete() except IntegrityError as e: - return Response(data=str(e), status=status.HTTP_400_BAD_REQUEST) + # TODO: Log the exception if logging is set up + # logging.exception("Integrity error while deleting library: %s", e) + print(e) except Exception as e: # TODO: Log the exception if logging is set up # logging.exception("Unexpected error while deleting library: %s", e) + print(e) return Response( data="Unexpected error occurred while deleting the library.", status=status.HTTP_500_INTERNAL_SERVER_ERROR,