Skip to content

Instantly share code, notes, and snippets.

@kapresoft
Last active May 12, 2023 01:10
Show Gist options
  • Save kapresoft/154d48098e52134703b7a2120b7dd4f8 to your computer and use it in GitHub Desktop.
Save kapresoft/154d48098e52134703b7a2120b7dd4f8 to your computer and use it in GitHub Desktop.
@ExceptionHandler(NotFoundException.class)
public ResponseEntity<HttpClientErrorException> handleNotFound(NotFoundException ex, WebRequest req) {
ProblemDetail p = ProblemDetail.forStatus(ex.getStatusCode());
URI type = new DefaultUriBuilderFactory()
.uriString("https://yoursite.acme.com/not-found/{error-code}")
.build(Map.of("error-code", ex.getErrorCode()));
p.setDetail(ex.getStatusText());
p.setTitle("Object not found");
p.setType(type);
p.setProperty("hint", "hint-value");
return ResponseEntity.of(p).build();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment