Browse Source

Returns Mono.error rather than empty to send 500 when hystrix has an error

fixes gh-75
pull/295/head
Spencer Gibb 7 years ago
parent
commit
1a3de526dd
No known key found for this signature in database
GPG Key ID: 7788A47380690861
  1. 2
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/HystrixGatewayFilterFactory.java
  2. 30
      spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/HystrixGatewayFilterFactoryTests.java

2
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/HystrixGatewayFilterFactory.java

@ -105,7 +105,7 @@ public class HystrixGatewayFilterFactory extends AbstractGatewayFilterFactory<Hy @@ -105,7 +105,7 @@ public class HystrixGatewayFilterFactory extends AbstractGatewayFilterFactory<Hy
return exchange.getResponse().setComplete();
}
}
return Mono.empty();
return Mono.error(throwable);
}).then();
};
}

30
spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/HystrixGatewayFilterFactoryTests.java

@ -20,15 +20,21 @@ package org.springframework.cloud.gateway.filter.factory; @@ -20,15 +20,21 @@ package org.springframework.cloud.gateway.filter.factory;
import java.util.Collections;
import java.util.Map;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ServerList;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.cloud.gateway.test.BaseWebClientTests;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.cloud.netflix.ribbon.StaticServerList;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.http.HttpStatus;
@ -89,10 +95,19 @@ public class HystrixGatewayFilterFactoryTests extends BaseWebClientTests { @@ -89,10 +95,19 @@ public class HystrixGatewayFilterFactoryTests extends BaseWebClientTests {
.expectBody().json("{\"from\":\"fallbackcontroller2\"}");
}
@Test
public void hystrixFilterConnectFailure() {
testClient.get().uri("/delay/3")
.header("Host", "www.hystrixconnectfail.org")
.exchange()
.expectStatus().is5xxServerError();
}
@EnableAutoConfiguration
@SpringBootConfiguration
@Import(DefaultTestConfig.class)
@RestController
@RibbonClient(name = "badservice", configuration = TestBadRibbonConfig.class)
public static class TestConfig {
@Value("${test.uri}")
@ -115,8 +130,23 @@ public class HystrixGatewayFilterFactoryTests extends BaseWebClientTests { @@ -115,8 +130,23 @@ public class HystrixGatewayFilterFactoryTests extends BaseWebClientTests {
.filters(f -> f.prefixPath("/httpbin")
.hystrix(config -> config.setFallbackUri("forward:/fallbackcontroller2")))
.uri(uri))
.route("hystrix_connection_failure", r -> r.host("**.hystrixconnectfail.org")
.filters(f -> f.prefixPath("/httpbin")
.hystrix(config -> {}))
.uri("lb:badservice"))
.build();
}
}
protected static class TestBadRibbonConfig {
@LocalServerPort
protected int port = 0;
@Bean
public ServerList<Server> ribbonServerList() {
return new StaticServerList<>(new Server("https", "localhost", this.port));
}
}
}

Loading…
Cancel
Save