Skip to content
Snippets Groups Projects

new handling for wrapped exception with custom message

Merged Tucker Gary Siegel requested to merge update into develop
2 files
+ 14
9
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -29,17 +29,21 @@ public class CustomExceptionHandler {
return exceptionAsString;
}
private ResponseEntity<Object> returnDawnException(DawnException exception) {
private void logException(DawnException exception) {
if (exception.getBase() != null) {
MDC.put("stackTrace", getStackTrace(exception.getBase()));
MDC.put("exceptionMessage", exception.getBase().getMessage());
} else {
MDC.put("stackTrace", getStackTrace(exception));
MDC.put("exceptionMessage", exception.getMessage());
// MDC.put("exceptionMessage", exception.)
}
log.error(exception.getMessage());
MDC.remove("stackTrace");
MDC.remove("exceptionMessage");
}
private ResponseEntity<Object> returnDawnException(DawnException exception) {
logException(exception);
return ExceptionResponse.fromDawnException(exception, source).toResponse();
}
@@ -51,15 +55,12 @@ public class CustomExceptionHandler {
@ExceptionHandler(BindException.class)
protected ResponseEntity<Object> handleBindException(BindException ex, WebRequest request) {
DawnException wrapped = new DawnException(BaseExceptions.BAD_REQUEST, ex);
FieldError err = ex.getFieldError();
wrapped.setDescription("Value " + err.getRejectedValue() + " is invalid for field " + err.getField());
ExceptionResponse response = ExceptionResponse.builder()
.source(source)
.description("Value " + err.getRejectedValue() + " is invalid for field " + err.getField())
.errorCode("BAD_REQUEST")
.build()
.buildDetails();
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
return returnDawnException(wrapped);
}
@ExceptionHandler(ArrayIndexOutOfBoundsException.class)
Loading