Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertx: How to get fail() status code in failure handler?

How can status code passed to RoutingContext.fail(int) be retrieved in failure handler (registered using Route.failureHandler)?

E.g. If processing of some route takes too long, it can be interrupted by TimeoutHandler that calls fail(408) on RoutingContext. fail method subsequently invokes failure handler (if registered). However I can't find any way (except for reflection & depending on implementation) how to find out in handler itself why it was called:

  • RoutingContext.failure() returns null
  • status code seems to be set only in private field of RoutingContextImpl, not yet in HttpServerResponse
like image 597
czerny Avatar asked Jan 27 '26 07:01

czerny


1 Answers

Not sure about older version of Vert.x, but from 3.0.0 an up:

eventBus.send("some.address", "some value", event -> {
  if (event.succeeded()) {
    System.out.println("Received reply: " + event.result().body());
  } else {
    ReplyException cause = (ReplyException) event.cause();
    String failMessage = cause.getMessage();
    int failCode = cause.failureCode();
  }
});
like image 93
NoamK Avatar answered Jan 29 '26 05:01

NoamK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!