Add UnexpectedServerException for centralized server error handling#13740
Add UnexpectedServerException for centralized server error handling#13740CodeByAfroj wants to merge 14 commits intoTEAMMATES:masterfrom
Conversation
Replaced JsonResult error handling with UnexpectedServerException for better error management.
Added handling for UnexpectedServerException in WebApiServlet.
|
Hi @CodeByAfroj, thank you for your interest in contributing to TEAMMATES!
Please address the above before we proceed to review your PR. |
|
Hi, I’ve submitted a PR for this issue. Please review it. |
Changed UnexpectedServerException to extend RuntimeException instead of Exception.
Added a comment to clarify the purpose of the exception.
| } catch (InvalidParametersException | EntityAlreadyExistsException | EntityDoesNotExistException e) { | ||
| // There should not be any invalid parameter or entity conflict here | ||
| log.severe("Unexpected error", e); | ||
| return new JsonResult(e.getMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR); |
There was a problem hiding this comment.
I believe this is not the only place this occurrence of returning a JsonResult with the HTTP 500 directly. For one, UnpublishFeedbackSessionAction has one of this instance.
There was a problem hiding this comment.
Thanks for giving me a feedback . I will Do the required changes ASAP.
| @@ -73,7 +74,7 @@ public JsonResult execute() throws InvalidHttpRequestBodyException, InvalidOpera | |||
| } catch (InvalidParametersException | EntityAlreadyExistsException | EntityDoesNotExistException e) { | |||
| // There should not be any invalid parameter or entity conflict here | |||
| log.severe("Unexpected error", e); | |||
There was a problem hiding this comment.
I suppose these logs were initially there because we bypassed the centralised error handling, which will otherwise have logged this unexpected error.
These redundant log.severe calls should be removed too since the centralised error handling already logs the error.
There was a problem hiding this comment.
I got this and thanks again , I will fix them .
Please address this too @CodeByAfroj |
Updated UnexpectedServerException to include error message.
|
Hi, I have addressed all the feedback and ensured that all checks are passing now. Kindly review. |
Fixes #13733
Outline of Solution
This PR introduces a new
UnexpectedServerExceptionto handle unexpected server-side errors in a centralized way.Changes made:
UnexpectedServerExceptionWebApiServletJsonResult(..., HttpStatus.SC_INTERNAL_SERVER_ERROR)returns with throwingUnexpectedServerExceptioninCreateAccountActionRationale:
Previously, some parts of the code returned HTTP 500 responses directly when unexpected checked exceptions occurred. This bypassed the centralized error handling in
WebApiServlet.This change ensures:
Testing:
WebApiServlet