|
8 | 8 | import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; |
9 | 9 | import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; |
10 | 10 |
|
11 | | -import java.sql.SQLException; |
12 | | - |
13 | 11 | /** |
14 | 12 | * Handles all Rest Exceptions. |
15 | 13 | */ |
@@ -42,14 +40,26 @@ public ResponseEntity<ErrorResponse> handleInvalidEntityIdException(@NotNull Inv |
42 | 40 | } |
43 | 41 |
|
44 | 42 | /** |
45 | | - * Handles all {@link SQLException}s. |
| 43 | + * Handles all {@link InternalServerException}s. |
46 | 44 | * |
47 | | - * @param e The {@link SQLException} which was thrown. |
| 45 | + * @param e The {@link InternalServerException} which was thrown. |
48 | 46 | * @return The {@link ResponseEntity} containing the {@link ErrorResponse}. |
49 | 47 | */ |
50 | | - @ExceptionHandler({ InternalServerException.class }) |
| 48 | + @ExceptionHandler(InternalServerException.class) |
51 | 49 | public ResponseEntity<ErrorResponse> handleInternalServerException(@NotNull InternalServerException e) { |
52 | | - ErrorResponse error = new ErrorResponse(HttpStatus.BAD_REQUEST, e.getCause().getLocalizedMessage(), e.getLocalizedMessage()); |
| 50 | + ErrorResponse error = new ErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, e.getCause().getLocalizedMessage(), e.getLocalizedMessage()); |
| 51 | + return new ResponseEntity<>(error, error.status()); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Handles all generic {@link Exception}. |
| 56 | + * |
| 57 | + * @param e The {@link Exception} which was thrown. |
| 58 | + * @return The {@link ResponseEntity} containing the {@link ErrorResponse}. |
| 59 | + */ |
| 60 | + @ExceptionHandler(Exception.class) |
| 61 | + public ResponseEntity<ErrorResponse> handleGenericException(@NotNull Exception e) { |
| 62 | + ErrorResponse error = new ErrorResponse(HttpStatus.BAD_REQUEST, e.getLocalizedMessage()); |
53 | 63 | return new ResponseEntity<>(error, error.status()); |
54 | 64 | } |
55 | 65 | } |
0 commit comments