Adds message back to response in case of timeout exception.
fixes gh-820
This commit is contained in:
@@ -87,6 +87,7 @@ public class NettyRoutingFilter implements GlobalFilter, Ordered {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("Duplicates")
|
||||
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||
URI requestUrl = exchange.getRequiredAttribute(GATEWAY_REQUEST_URL_ATTR);
|
||||
|
||||
@@ -174,7 +175,9 @@ public class NettyRoutingFilter implements GlobalFilter, Ordered {
|
||||
if (properties.getResponseTimeout() != null) {
|
||||
responseFlux = responseFlux.timeout(properties.getResponseTimeout(),
|
||||
Mono.error(new TimeoutException("Response took longer than timeout: " +
|
||||
properties.getResponseTimeout()))).onErrorMap(TimeoutException.class, th -> new ResponseStatusException(HttpStatus.GATEWAY_TIMEOUT, null, th));
|
||||
properties.getResponseTimeout())))
|
||||
.onErrorMap(TimeoutException.class,
|
||||
th -> new ResponseStatusException(HttpStatus.GATEWAY_TIMEOUT, th.getMessage(), th));
|
||||
}
|
||||
|
||||
return responseFlux.then(chain.filter(exchange));
|
||||
|
||||
@@ -44,7 +44,8 @@ public class NettyRoutingFilterIntegrationTests extends BaseWebClientTests {
|
||||
.exchange()
|
||||
.expectStatus().isEqualTo(HttpStatus.GATEWAY_TIMEOUT)
|
||||
.expectBody()
|
||||
.jsonPath("$.status").isEqualTo(String.valueOf(HttpStatus.GATEWAY_TIMEOUT.value()));
|
||||
.jsonPath("$.status").isEqualTo(String.valueOf(HttpStatus.GATEWAY_TIMEOUT.value()))
|
||||
.jsonPath("$.message").isEqualTo("Response took longer than timeout: PT3S");
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
|
||||
Reference in New Issue
Block a user