a-n-u-p-01 / Journal-Rest-API

Open to contribute, improve your debug skill by contributing this project. Thank you!
6 stars 1 forks source link

Enhance Exception Handling and Implement Global Exception Handler for UserNotFoundException #4

Closed a-n-u-p-01 closed 1 week ago

a-n-u-p-01 commented 2 weeks ago

Global Exception Handling for UserNotFoundException

Overview

This implementation enhances the exception handling mechanism within the application by defining a custom exception, UserNotFoundException, and implementing a global exception handler to manage this exception effectively. The goal is to centralize exception handling, improving code maintainability and consistency.

Tasks

1. Define UserNotFoundException

2. Implement Global Exception Handler

3. Refactor Existing Code

Guhapriya01 commented 2 weeks ago

Hi @a-n-u-p-01,

I’m currently working on this issue and noticed a scenario where an admin might try to delete their own account using the DELETE /user route. Currently, for both cases—user not existing and admin users—the DELETE /user route returns a "User Not Found" response.

For the DELETE /admin/{userName} route, a 403 Forbidden response is returned when an admin tries to delete another admin user or themselves.

I’d like to clarify a couple of points:

I also noticed there's an open issue about handling the deletion of users with the "ADMIN" role. I want to ensure that my implementation aligns with the expected behavior for admin deletions. Please let me know your thoughts!

a-n-u-p-01 commented 2 weeks ago

Steps:

If you have any other ideas or methods in mind for implementing this process, feel free to share.

Guhapriya01 commented 2 weeks ago

Thank you for the clarification. Based on your requirements, here’s how I plan to implement the admin role transfer and deletion process:

For the DELETE /admin/{username} Route:

For the DELETE /user Route:

Please let me know if this approach aligns with your expectations or if there are any additional considerations I should keep in mind.