Skip to content

Instantly share code, notes, and snippets.

@Raouf25
Created April 24, 2020 17:14
Show Gist options
  • Save Raouf25/ee452d39a95269a663f2877667ae8df4 to your computer and use it in GitHub Desktop.
Save Raouf25/ee452d39a95269a663f2877667ae8df4 to your computer and use it in GitHub Desktop.
@ControllerAdvice
@CrossOrigin
public class ExceptionHandlerController {
@ExceptionHandler({ClientUnavailableException.class})
public ResponseEntity<ErrorAndCodeResponse> badRequest(BackendException e) {
ErrorAndCodeResponse error = new ErrorAndCodeResponse(e.getCode().name(), e.getCode().getMessage(), e.getAdditionalInfo());
return new ResponseEntity<>(error, HttpStatus.BAD_REQUEST);
}
@ExceptionHandler(ResourceNotFoundException.class)
public ResponseEntity<ErrorAndCodeResponse> notFound(BackendException e) {
ErrorAndCodeResponse error = new ErrorAndCodeResponse(e.getCode().name(), e.getCode().getMessage(), e.getAdditionalInfo());
return new ResponseEntity<>(error, HttpStatus.NOT_FOUND);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment