Last active
January 3, 2021 04:36
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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