From a76cb1bea9f831cd106e46176afbebfed3a4eb66 Mon Sep 17 00:00:00 2001 From: Tucker Siegel <tgsiegel@terpmail.umd.edu> Date: Wed, 12 Apr 2023 18:23:06 -0400 Subject: [PATCH] expand --- .../exceptions/CustomExceptionHandler.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/edu/umd/dawn/common/exceptions/CustomExceptionHandler.java b/src/main/java/edu/umd/dawn/common/exceptions/CustomExceptionHandler.java index c9c0669..213db06 100644 --- a/src/main/java/edu/umd/dawn/common/exceptions/CustomExceptionHandler.java +++ b/src/main/java/edu/umd/dawn/common/exceptions/CustomExceptionHandler.java @@ -51,6 +51,11 @@ public class CustomExceptionHandler { return returnDawnException(wrapped); } + private ResponseEntity<Object> wrapExceptionAs(Exception exception, DawnExceptionParameters parameters) { + DawnException wrapped = new DawnException(parameters, exception); + return returnDawnException(wrapped); + } + @ExceptionHandler(BindException.class) protected ResponseEntity<Object> handleBindException(BindException ex, WebRequest request) { @@ -68,14 +73,24 @@ public class CustomExceptionHandler { ArrayIndexOutOfBoundsException exception, WebRequest webRequest) { return wrapExceptionAs(exception, BaseExceptions.OUT_OF_BOUNDS); } + + @ExceptionHandler(DawnException.class) + public ResponseEntity<Object> handleDawnExceptions(DawnException exception, WebRequest webRequest) { + return returnDawnException(exception); + } @ExceptionHandler(RuntimeException.class) public ResponseEntity<Object> handleUnHandledException(RuntimeException exception, WebRequest webRequest) { return wrapExceptionAs(exception, BaseExceptions.UNHANDLED_INTERNAL_SERVER_ERROR); } - @ExceptionHandler(DawnException.class) - public ResponseEntity<Object> handleDawnExceptions(DawnException exception, WebRequest webRequest) { - return returnDawnException(exception); + @ExceptionHandler(Exception.class) + public ResponseEntity<Object> handleUnHandledException(Exception exception, WebRequest webRequest) { + return wrapExceptionAs(exception, BaseExceptions.UNHANDLED_INTERNAL_SERVER_ERROR); + } + + @ExceptionHandler(Throwable.class) + public ResponseEntity<Object> handleUnHandledException(Throwable exception, WebRequest webRequest) { + return wrapExceptionAs((Exception)exception, BaseExceptions.UNHANDLED_INTERNAL_SERVER_ERROR); } } -- GitLab