Closed a-n-u-p-01 closed 1 week 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:
DELETE /user
route, or should this be restricted?403 Forbidden
response for the DELETE /user
route, similar to the DELETE /admin/{userName}
route, or is there a different response you’d suggest?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!
Steps:
If you have any other ideas or methods in mind for implementing this process, feel free to share.
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.
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
UserNotFoundException
.UserNotFoundException
in theexception
package.UserNotFoundException
extendsRuntimeException
.2. Implement Global Exception Handler
UserNotFoundException
.GlobalExceptionHandler
in theexception
package.@ControllerAdvice
to allow it to handle exceptions globally across all controllers.@ExceptionHandler
annotation within this class to define a method that handlesUserNotFoundException
.404 Not Found
) and a meaningful error message.3. Refactor Existing Code
UserNotFoundException
.try-catch
blocks or local handling ofUserNotFoundException
within controller methods.