Skip to content

Commit

Permalink
[#8]
Browse files Browse the repository at this point in the history
add cause field to ErrorResponse
  • Loading branch information
jj committed Feb 27, 2019
1 parent e9682d0 commit 46a291d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@
public class ErrorResponse {
private String errorCode;
private String errorMessage;
private String cause;

public ErrorResponse(String errorCode, String errorMessage) {
this(errorCode, errorMessage, null);
}

public ErrorResponse(HttpStatus httpStatus, String errorMessage) {
this.errorCode = String.valueOf(httpStatus.value());
this.errorMessage = errorMessage;
this(httpStatus, errorMessage, null);
}

public ErrorResponse(HttpStatus httpStatus, String errorCode, String cause) {
this(String.valueOf(httpStatus.value()), errorCode, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class MetadataResolversController {

@ExceptionHandler({InvalidTypeIdException.class, IOException.class, HttpMessageNotReadableException.class})
public ResponseEntity<?> unableToParseJson(Exception ex) {
return ResponseEntity.badRequest().body(new ErrorResponse(HttpStatus.BAD_REQUEST.toString(), ex.getMessage()));
return ResponseEntity.badRequest().body(new ErrorResponse(HttpStatus.BAD_REQUEST.toString(), ex.getMessage(), ex.getCause().getMessage()));
}

@GetMapping("/MetadataResolvers")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public ResponseEntity<ErrorResponse> handleDatabaseConstraintViolation(Constrain

@ExceptionHandler(Exception.class)
public final ResponseEntity<ErrorResponse> handleAllOtherExceptions(Exception ex) {
ErrorResponse errorResponse = new ErrorResponse("400", ex.getLocalizedMessage());
ErrorResponse errorResponse = new ErrorResponse("400", ex.getLocalizedMessage(), ex.getCause().getLocalizedMessage());
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
}

Expand Down

0 comments on commit 46a291d

Please sign in to comment.