I have a reverse proxy server using Vert.x Web Proxy, implemented with pretty standard code:
...
HttpClient client = theVertx.createHttpClient();
HttpProxy proxy = HttpProxy.reverseProxy(client);
Route anyroute = theRouter.route("/*");
anyroute.handler(ProxyHandler.create(proxy));
anyroute.failureHandler(hnd->{
System.out.println("Failure. Return code: "+hnd.response().getStatusCode());
});
...
This code works well enough, but I would like to be able to capture return codes in order to do some custom actions (like displaying custom web pages when 400 failures occur). I am seeing that the code in the failureHandler() method is not being called when I cause a 404 error to occur. Apparently, what happens is that if I make a request for a resource that doe not exist on the target server, the proxy actually returns the 404 error sent by the target server back to the browser!
I would like to capture that 404 error when the proxy receives it and do something with it. Unfortunately, it is unclear from the web proxy documentation (or any of the rather few code examples I have seen on the web) that the web proxy is even capable of doing this.
Is it possible to write a handler that can capture the response that comes from an HttpProxy? If it is, how would I do this?