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 c9c06698e44c45f4ef3adfbe5072a27116f27e1d..213db06ee716ea88eb0fe8457d3f09495df8f546 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); } }