Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dinukadev
Created June 10, 2020 23:00
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 dinukadev/73245d97dad2c407af5223502d96105d to your computer and use it in GitHub Desktop.
Save dinukadev/73245d97dad2c407af5223502d96105d to your computer and use it in GitHub Desktop.
@ControllerAdvice(annotations = RestController.class)
public class ExceptionHandlerAdvice {
@ExceptionHandler(InvalidDataException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ResponseEntity<String> handleInvalidDataExceptions(InvalidDataException e) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.TEXT_PLAIN);
return new ResponseEntity<>(e.getMessage(), headers, HttpStatus.BAD_REQUEST);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment