Решил сделать через фильтр, вдруг кому-нибудь пригодится:
@Slf4j
@Component
public class LoggingExchangeFilterFunction implements ExchangeFilterFunction {
@Override
public Mono<ClientResponse> filter(ClientRequest request, ExchangeFunction next) {
return next.exchange(request)
.doOnNext(response -> {
HttpStatus status = response.statusCode();
if (status.is4xxClientError() || status.is5xxServerError()){
logErrorResponse(request, response);
}
});
}
private void logErrorResponse(ClientRequest request, ClientResponse response) {
log.error("Error response for request: {} {}", request.method(), request.url());
log.error("Response status: {}", response.statusCode());
response.bodyToMono(String.class)
.doOnNext(body -> log.error("Response body: {}", body))
.subscribe();
}
}