Skip to content

Instantly share code, notes, and snippets.

@sandipchitale
Created November 10, 2023 05:15
Show Gist options
  • Save sandipchitale/381f0060befb8b8f67ac61042dedafe7 to your computer and use it in GitHub Desktop.
Save sandipchitale/381f0060befb8b8f67ac61042dedafe7 to your computer and use it in GitHub Desktop.
ErrorHandling #spring-web-mvc
@ExceptionHandler(Exception.class)
public ResponseEntity<String> handleError(HttpServletRequest req, Exception ex) {
if (ex.getCause() instanceof SocketTimeoutException) {
return ResponseEntity.status(HttpStatus.GATEWAY_TIMEOUT).body(HttpStatus.GATEWAY_TIMEOUT.getReasonPhrase());
}
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment