In the event that a route exists and the downstream service is not available, usually the Gateway returns a 503 status code as expected.
On a dynamic environment though, such as k8s and docker compose, the underlying error results from a DNS lookup failure, and the default error is 500 instead.
A custom org.springframework.boot.web.reactive.error.ErrorAttributes is now used to override the DefaultErrorAttributes configured in ErrorWebFluxAutoConfiguration and injected to the ErrorWebExceptionHandler, and translates java.net.UnknownHostException and java.net.ConnectException to HttpStatus.SERVICE_UNAVAILABLE instead.
In the event that a route exists and the downstream service is not available, usually the Gateway returns a 503 status code as expected.
On a dynamic environment though, such as k8s and docker compose, the underlying error results from a DNS lookup failure, and the default error is 500 instead.
A custom
org.springframework.boot.web.reactive.error.ErrorAttributes
is now used to override theDefaultErrorAttributes
configured inErrorWebFluxAutoConfiguration
and injected to theErrorWebExceptionHandler
, and translatesjava.net.UnknownHostException
andjava.net.ConnectException
toHttpStatus.SERVICE_UNAVAILABLE
instead.