Handle NoSuchBucket Exception Gracefully and Provide User-Friendly Error Response
chavda-bhavik opened this issue · comments
- When a developer provides S3 details to the application and the application starts storing files in S3, the AWS SDK throws a
NoSuchBucket exception
if the specified bucket does not exist. - Currently, this exception is not handled gracefully, leading to a backend application crash.
- To improve the user experience, we should control this exception and return a user-friendly error response to the frontend instead of crashing the backend application.
- It's an important case when working with
Localstack
on local computer.
Steps to Reproduce:
- Provide valid S3 details, and invalid bucket name in the API env configuration.
- Start the application.
- Attempt to store a file in S3 using the application.
Current Behavior:
The backend application crashes with a NoSuchBucket exception
when the specified bucket does not exist.
Expected Behavior:
The application should handle the NoSuchBucket exception
gracefully and return a well-formatted error response to the front end, indicating that the specified bucket does not exist.
Proposed Solution:
- Catch the NoSuchBucket exception when interacting with the AWS SDK.
- Instead of letting the exception propagate and crash the application, handle it with
try...catch
and construct an error response. - Include relevant information in the error response, such as the bucket name provided by the developer.
- Return the error response to the frontend for display.
Additional Information:
- It would be beneficial to log the exception for debugging purposes.
Priority:
High