From 4dfb3049c8c47290fd8e957642e42a7aa2a5d708 Mon Sep 17 00:00:00 2001 From: Antoine Dewez <44063631+Zewed@users.noreply.github.com> Date: Fri, 26 Jul 2024 16:38:01 +0200 Subject: [PATCH] fix(backend): fix error messages (#2917) # Description Please include a summary of the changes and the related issue. Please also include relevant motivation and context. ## Checklist before requesting a review Please delete options that are not relevant. - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented hard-to-understand areas - [ ] I have ideally added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged ## Screenshots (if appropriate): --- .../quivr_api/modules/sync/utils/upload.py | 22 +++++++++++++------ .../upload/controller/upload_routes.py | 22 +++++++++++++------ 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/backend/api/quivr_api/modules/sync/utils/upload.py b/backend/api/quivr_api/modules/sync/utils/upload.py index 2bab7abee..8ce23d1de 100644 --- a/backend/api/quivr_api/modules/sync/utils/upload.py +++ b/backend/api/quivr_api/modules/sync/utils/upload.py @@ -62,19 +62,27 @@ async def upload_file( except Exception as e: print(e) - notification_service.update_notification_by_id( - notification_id, - NotificationUpdatableProperties( - status=NotificationsStatusEnum.ERROR, - description=f"There was an error uploading the file: {e}", - ), - ) if "The resource already exists" in str(e): + notification_service.update_notification_by_id( + notification_id, + NotificationUpdatableProperties( + status=NotificationsStatusEnum.ERROR, + description=f"File {upload_file.filename} already exists in storage.", + ), + ) raise HTTPException( status_code=403, detail=f"File {upload_file.filename} already exists in storage.", ) + else: + notification_service.update_notification_by_id( + notification_id, + NotificationUpdatableProperties( + status=NotificationsStatusEnum.ERROR, + description=f"There was an error uploading the file", + ), + ) raise HTTPException( status_code=500, detail=f"Failed to upload file to storage. {e}" ) diff --git a/backend/api/quivr_api/modules/upload/controller/upload_routes.py b/backend/api/quivr_api/modules/upload/controller/upload_routes.py index c466b4e5b..02517c675 100644 --- a/backend/api/quivr_api/modules/upload/controller/upload_routes.py +++ b/backend/api/quivr_api/modules/upload/controller/upload_routes.py @@ -82,19 +82,27 @@ async def upload_file( except Exception as e: print(e) - notification_service.update_notification_by_id( - upload_notification.id if upload_notification else None, - NotificationUpdatableProperties( - status=NotificationsStatusEnum.ERROR, - description=f"There was an error uploading the file: {e}", - ), - ) + if "The resource already exists" in str(e): + notification_service.update_notification_by_id( + upload_notification.id if upload_notification else None, + NotificationUpdatableProperties( + status=NotificationsStatusEnum.ERROR, + description=f"File {uploadFile.filename} already exists in storage.", + ), + ) raise HTTPException( status_code=403, detail=f"File {uploadFile.filename} already exists in storage.", ) else: + notification_service.update_notification_by_id( + upload_notification.id if upload_notification else None, + NotificationUpdatableProperties( + status=NotificationsStatusEnum.ERROR, + description=f"There was an error uploading the file", + ), + ) raise HTTPException( status_code=500, detail=f"Failed to upload file to storage. {e}" )