Skip to content

Instantly share code, notes, and snippets.

@skaveesh
Last active January 3, 2021 04:36
Show Gist options
  • Save skaveesh/534c3454c74d251e51d0e86c5818d8e1 to your computer and use it in GitHub Desktop.
Save skaveesh/534c3454c74d251e51d0e86c5818d8e1 to your computer and use it in GitHub Desktop.
How I Decoupled Circuit Breaker from the Code with AOP in Spring Boot for Better Code Maintenance
//code is omitted for brevity
@RestControllerAdvice
@Component
public class ApplicationResponseEntityExceptionHandler extends ResponseEntityExceptionHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationResponseEntityExceptionHandler.class);
@ExceptionHandler(CircuitBreakerDownstreamCallException.class)
public ResponseEntity<Map<String, Object>> handleException(final Exception exception, final HttpServletRequest request) {
LOGGER.error("Downstream call Exception: {} ", exception.getMessage(), exception);
Map<String, Object> responseBody = new HashMap<>();
HttpStatus httpStatus = HttpStatus.GATEWAY_TIMEOUT;
responseBody.put(exception.getMessage(), httpStatus.value());
return new ResponseEntity<>(responseBody, httpStatus);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment