Created
December 9, 2018 11:37
-
-
Save h4t0n/c503c81b11a2917d7b191a5aef09aeff to your computer and use it in GitHub Desktop.
[GEMINI] ExceptionHandlerExample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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