Skip to content

Instantly share code, notes, and snippets.

@geraldoyudo
Last active September 10, 2018 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geraldoyudo/266f984cd8346b82dc296c69c187f7e1 to your computer and use it in GitHub Desktop.
Save geraldoyudo/266f984cd8346b82dc296c69c187f7e1 to your computer and use it in GitHub Desktop.
java-tutorials/api-error-handling/hello-controller-advice-with-status
@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