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):
This commit is contained in:
Antoine Dewez 2024-07-26 16:38:01 +02:00 committed by GitHub
parent 6359cff5cc
commit 4dfb3049c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 14 deletions

View File

@ -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}"
)

View File

@ -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}"
)