I have a custom exception class annotated to return a given HttpStatus
:
@ResponseStatus(value=HttpStatus.BAD_REQUEST, reason=\"Invalid parameter\")
Since spring 5.0, you can use the ResponseStatusException
which is available
// From https://www.baeldung.com/spring-response-status-exception @GetMapping("/actor/{id}") public String getActorName(@PathVariable("id") int id) { try { return actorService.getActor(id); } catch (ActorNotFoundException ex) { throw new ResponseStatusException( HttpStatus.NOT_FOUND, "Actor Not Found", ex); } }