vertx-http-proxy icon indicating copy to clipboard operation
vertx-http-proxy copied to clipboard

ExceptionHandler for send requests and proxy responses in `HttpProxy`/`ReverseProxy`

Open fbuetler opened this issue 9 months ago • 1 comments

Describe the feature

In case any interceptor fails with an exception, it is handled as a 502.

We propose to introduce an exceptionHandler in the HttpProxy to customize this behavior, analogously it is done in the HttpServerRequest, HttpServerResponse and many others.

Relevant code:

    proxy.sendRequest()
      .recover(throwable -> {
        log.trace("Error in sending the request", throwable);
        return Future.succeededFuture(proxyRequest.release().response().setStatusCode(502));
      })
      .compose(proxy::sendProxyResponse)
      .recover(throwable -> {
        log.trace("Error in sending the response", throwable);
        return proxy.response().release().setStatusCode(502).send();
      });

(Source: https://github.com/eclipse-vertx/vertx-http-proxy/blob/4.5.13/src/main/java/io/vertx/httpproxy/impl/ReverseProxy.java#L78-L87)

Use cases

When applying interceptors, the proxy may want to return status codes that differ to the hard-coded 502.

Contribution

I volunteer to implement this feature.

We propose to add the following methods to HttpProxy and ReverseProxy:

  HttpProxy requestExceptionHandler(Handler<Throwable> handler);
  HttpProxy responseExceptionHandler(Handler<Throwable> handler);

Alternatively, only exceptionHandler may be added that is to be used on both request and responses.

fbuetler avatar Feb 25 '25 10:02 fbuetler

Ok I see, the default exception handler would take care of send 502 ?

vietj avatar Feb 26 '25 20:02 vietj

@tsegismont this fix must be in 4.5.17 as I faced this issue today while upgrading from 4.5.14 to 4.5.15. It took a lot of time to understand the issue until I enabled the io.vertx logs on trace mode.

RajawatBanna avatar Jul 26 '25 16:07 RajawatBanna