Skip to content

Instantly share code, notes, and snippets.

@h4t0n
Created December 9, 2018 11:37
Show Gist options
  • Save h4t0n/c503c81b11a2917d7b191a5aef09aeff to your computer and use it in GitHub Desktop.
Save h4t0n/c503c81b11a2917d7b191a5aef09aeff to your computer and use it in GitHub Desktop.
[GEMINI] ExceptionHandlerExample
@ExceptionHandler(EntityRecordException.class)
public ResponseEntity<?> handleEntityFoundException(EntityRecordException exception) {
HttpStatus httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;
switch (exception.getErrorCode()) {
case MULTIPLE_LK_FOUND:
httpStatus = HttpStatus.CONFLICT;
break;
case LK_NOTFOUND:
case INSERTED_RECORD_NOT_FOUND:
httpStatus = HttpStatus.NOT_FOUND;
break;
}
return new ResponseEntity<>(new ApiError(httpStatus, exception.getErrorCodeName(), exception.getMessage()), httpStatus);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment