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 {
@@ -29,17 +29,21 @@ public class CustomExceptionHandler {
return exceptionAsString;
return exceptionAsString;
}
}
private ResponseEntity<Object> returnDawnException(DawnException exception) {
private void logException(DawnException exception) {
if (exception.getBase() != null) {
if (exception.getBase() != null) {
MDC.put("stackTrace", getStackTrace(exception.getBase()));
MDC.put("stackTrace", getStackTrace(exception.getBase()));
MDC.put("exceptionMessage", exception.getBase().getMessage());
MDC.put("exceptionMessage", exception.getBase().getMessage());
} else {
} else {
MDC.put("stackTrace", getStackTrace(exception));
MDC.put("stackTrace", getStackTrace(exception));
MDC.put("exceptionMessage", exception.getMessage());
MDC.put("exceptionMessage", exception.getMessage());
// MDC.put("exceptionMessage", exception.)
}
}
log.error(exception.getMessage());
log.error(exception.getMessage());
MDC.remove("stackTrace");
MDC.remove("stackTrace");
 
MDC.remove("exceptionMessage");
 
}
 
 
private ResponseEntity<Object> returnDawnException(DawnException exception) {
 
logException(exception);
return ExceptionResponse.fromDawnException(exception, source).toResponse();
return ExceptionResponse.fromDawnException(exception, source).toResponse();
}
}
@@ -51,15 +55,12 @@ public class CustomExceptionHandler {
@@ -51,15 +55,12 @@ public class CustomExceptionHandler {
@ExceptionHandler(BindException.class)
@ExceptionHandler(BindException.class)
protected ResponseEntity<Object> handleBindException(BindException ex, WebRequest request) {
protected ResponseEntity<Object> handleBindException(BindException ex, WebRequest request) {
 
DawnException wrapped = new DawnException(BaseExceptions.BAD_REQUEST, ex);
 
FieldError err = ex.getFieldError();
FieldError err = ex.getFieldError();
 
wrapped.setDescription("Value " + err.getRejectedValue() + " is invalid for field " + err.getField());
ExceptionResponse response = ExceptionResponse.builder()
return returnDawnException(wrapped);
.source(source)
.description("Value " + err.getRejectedValue() + " is invalid for field " + err.getField())
.errorCode("BAD_REQUEST")
.build()
.buildDetails();
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
}
}
@ExceptionHandler(ArrayIndexOutOfBoundsException.class)
@ExceptionHandler(ArrayIndexOutOfBoundsException.class)
Loading