Skip to content
Snippets Groups Projects
Commit fd37b6f3 authored by Tucker Gary Siegel's avatar Tucker Gary Siegel
Browse files

new handling for wrapped exception with custom message

parent af0bafd6
No related branches found
No related tags found
1 merge request!2new handling for wrapped exception with custom message
......@@ -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)
......
......@@ -34,4 +34,8 @@ public class DawnException extends RuntimeException {
}
return super.getStackTrace();
}
public void setDescription(String description) {
this.description = description;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment