Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.