Skip to content

Commit 4936355

Browse files
committed
Update loadbalancer exceptions to 503 Service Unavailable
1 parent 9ad7b07 commit 4936355

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

spring-cloud-gateway-server-mvc/src/main/java/org/springframework/cloud/gateway/server/mvc/filter/LoadBalancerFilterFunctions.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
import org.springframework.cloud.gateway.server.mvc.common.MvcUtils;
4242
import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory;
4343
import org.springframework.http.HttpHeaders;
44+
import org.springframework.http.HttpStatus;
4445
import org.springframework.util.MultiValueMap;
46+
import org.springframework.web.client.HttpServerErrorException;
4547
import org.springframework.web.servlet.function.HandlerFilterFunction;
4648
import org.springframework.web.servlet.function.ServerResponse;
4749

@@ -73,16 +75,16 @@ public static HandlerFilterFunction<ServerResponse, ServerResponse> lb(String se
7375

7476
LoadBalancerClient loadBalancerClient = clientFactory.getInstance(serviceId, LoadBalancerClient.class);
7577
if (loadBalancerClient == null) {
76-
// TODO: type, return 500 error?
77-
throw new RuntimeException("No loadbalancer available for " + serviceId);
78+
throw new HttpServerErrorException(HttpStatus.SERVICE_UNAVAILABLE,
79+
"No loadbalancer available for " + serviceId);
7880
}
7981
supportedLifecycleProcessors.forEach(lifecycle -> lifecycle.onStart(lbRequest));
8082
ServiceInstance retrievedInstance = loadBalancerClient.choose(serviceId, lbRequest);
8183
if (retrievedInstance == null) {
8284
supportedLifecycleProcessors.forEach(lifecycle -> lifecycle
8385
.onComplete(new CompletionContext<>(CompletionContext.Status.DISCARD, lbRequest)));
84-
// TODO: type, return 500 error?
85-
throw new RuntimeException("Unable to find instance for " + serviceId);
86+
throw new HttpServerErrorException(HttpStatus.SERVICE_UNAVAILABLE,
87+
"Unable to find instance for " + serviceId);
8688
// throw NotFoundException.create(properties.isUse404(), "Unable to find
8789
// instance for " + serviceId);
8890
}

0 commit comments

Comments
 (0)