Skip to content

Instantly share code, notes, and snippets.

@kapresoft
Last active May 12, 2023 01:11
Show Gist options
  • Save kapresoft/68678f59798be7fd36dd4a96db9a132f to your computer and use it in GitHub Desktop.
Save kapresoft/68678f59798be7fd36dd4a96db9a132f to your computer and use it in GitHub Desktop.
@ExceptionHandler(BadRequestException.class)
public ResponseEntity<HttpClientErrorException> handleBadRequest(BadRequestException ex, WebRequest req) {
ProblemDetail p = ProblemDetail.forStatus(ex.getStatusCode());
URI type = new DefaultUriBuilderFactory()
.uriString("https://yoursite.acme.com/bad-request/{error-code}")
.build(Map.of("error-code", ex.getErrorCode()));
p.setDetail(ex.getStatusText());
p.setTitle("Bad Request");
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