Created
July 14, 2021 15:19
-
-
Save erdemaydin/5c7ac453310d11934c3ae445faa3c009 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @ExceptionHandler(Exception.class) | |
| @ResponseBody ResponseEntity<TaskApiError> exceptionHandler(Throwable exception) { | |
| ResponseEntity apiError; | |
| if(exception instanceof InvalidInputException) { | |
| apiError = generateErrorResponse(TaskApiErrorType.INVALID_INPUT_ERROR, HttpStatus.BAD_REQUEST, exception); | |
| } else if (exception instanceof RecordNotFoundException) { | |
| apiError = generateErrorResponse(TaskApiErrorType.RECORD_NOT_FOUND_ERROR, HttpStatus.NOT_FOUND, exception); | |
| } else if (exception instanceof IllegalArgumentException || exception instanceof ValidationException || exception instanceof SessionException) { | |
| apiError = generateErrorResponse(TaskApiErrorType.ILLEGAL_ARGUMENTS_ERROR, HttpStatus.NOT_ACCEPTABLE, exception); | |
| } else { | |
| apiError = generateErrorResponse(TaskApiErrorType.UNHANDLED_ERROR, HttpStatus.FORBIDDEN, exception); | |
| } | |
| return apiError; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment