Last active
September 10, 2018 20:42
-
-
Save geraldoyudo/266f984cd8346b82dc296c69c187f7e1 to your computer and use it in GitHub Desktop.
java-tutorials/api-error-handling/hello-controller-advice-with-status
This file contains 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
@RestControllerAdvice | |
public class HelloControllerAdvice { | |
@ExceptionHandler(Exception.class) | |
public ResponseEntity<ApiError> handleGeneralException(){ | |
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) | |
.body( | |
ApiError.builder() | |
.error("Syntax Error (from controller-advice)") | |
.errorCode(500) | |
.build() | |
); | |
} | |
@ExceptionHandler(SyntaxException.class) | |
@ResponseStatus(HttpStatus.BAD_REQUEST) | |
public ApiError handleSyntaxException(){ | |
return ApiError.builder() | |
.error("Syntax Error (from controller-advice)") | |
.errorCode(991) | |
.build(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment