|
41 | 41 | import org.springframework.cloud.gateway.server.mvc.common.MvcUtils; |
42 | 42 | import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory; |
43 | 43 | import org.springframework.http.HttpHeaders; |
| 44 | +import org.springframework.http.HttpStatus; |
44 | 45 | import org.springframework.util.MultiValueMap; |
| 46 | +import org.springframework.web.client.HttpServerErrorException; |
45 | 47 | import org.springframework.web.servlet.function.HandlerFilterFunction; |
46 | 48 | import org.springframework.web.servlet.function.ServerResponse; |
47 | 49 |
|
@@ -73,16 +75,16 @@ public static HandlerFilterFunction<ServerResponse, ServerResponse> lb(String se |
73 | 75 |
|
74 | 76 | LoadBalancerClient loadBalancerClient = clientFactory.getInstance(serviceId, LoadBalancerClient.class); |
75 | 77 | 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); |
78 | 80 | } |
79 | 81 | supportedLifecycleProcessors.forEach(lifecycle -> lifecycle.onStart(lbRequest)); |
80 | 82 | ServiceInstance retrievedInstance = loadBalancerClient.choose(serviceId, lbRequest); |
81 | 83 | if (retrievedInstance == null) { |
82 | 84 | supportedLifecycleProcessors.forEach(lifecycle -> lifecycle |
83 | 85 | .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); |
86 | 88 | // throw NotFoundException.create(properties.isUse404(), "Unable to find |
87 | 89 | // instance for " + serviceId); |
88 | 90 | } |
|
0 commit comments