Vertx-Web :: webclient and unexpected exception.

373 views
Skip to first unread message

Hidwulf

unread,
Jul 24, 2017, 12:02:11 PM7/24/17
to vert.x
Hi,

I'm working on a api project using vertx-web, basic Rest API.

I'm missing something about the exception, whenever it occurs I can saw that vertx is triggering a http 500.

But when an exception occurs, not expected (bad code or bad data for example), vertx just doesn't send anything to the client anymore, so in postman or something else the client is still waiting!

Ex: in my default handler (trigger by my verticle) I do this

WebClient client = ...

int j = 1 / 0; // Instruction A

client.send( handler -> {

     int i = 1 / 0; // Instruction B

});


I this specific case:
  • instruction A generate a nullpointer and it's fine my app will respond with an http 500
  • instruction B (meaning I delete A of course), generate a nullpointer in the output but do nothing more and the client is still waiting.
Any clue? I don't really want to perform a try catch, I already transforme the thing into future plus compose but it doesn't appeal me.

Thanks.

Thomas SEGISMONT

unread,
Jul 24, 2017, 12:19:53 PM7/24/17
to ve...@googlegroups.com
When Vert.x Web invokes your handler, it happens inside a try/catch so any exception thrown by the handler call will result in failing the routing context.

When the web client handler is invoked, we're no longer inside this try/catch so the routing context cannot be automatically failed.

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/803b2e70-eba5-4e0a-b31b-28271256e1e4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hidwulf

unread,
Jul 25, 2017, 3:22:50 AM7/25/17
to vert.x
Thank for the answer.

Btw I'm not very happy with the response, so it means that to bulletproof my code I have to always start a handler for a webClient with a try...catch?

Please tell me that we could find a better solution.


Le lundi 24 juillet 2017 18:19:53 UTC+2, Thomas Segismont a écrit :
When Vert.x Web invokes your handler, it happens inside a try/catch so any exception thrown by the handler call will result in failing the routing context.

When the web client handler is invoked, we're no longer inside this try/catch so the routing context cannot be automatically failed.
2017-07-24 18:02 GMT+02:00 Hidwulf <hid...@gmail.com>:
Hi,

I'm working on a api project using vertx-web, basic Rest API.

I'm missing something about the exception, whenever it occurs I can saw that vertx is triggering a http 500.

But when an exception occurs, not expected (bad code or bad data for example), vertx just doesn't send anything to the client anymore, so in postman or something else the client is still waiting!

Ex: in my default handler (trigger by my verticle) I do this

WebClient client = ...

int j = 1 / 0; // Instruction A

client.send( handler -> {

     int i = 1 / 0; // Instruction B

});


I this specific case:
  • instruction A generate a nullpointer and it's fine my app will respond with an http 500
  • instruction B (meaning I delete A of course), generate a nullpointer in the output but do nothing more and the client is still waiting.
Any clue? I don't really want to perform a try catch, I already transforme the thing into future plus compose but it doesn't appeal me.

Thanks.

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.

Thomas SEGISMONT

unread,
Jul 25, 2017, 3:46:43 AM7/25/17
to ve...@googlegroups.com
If you want that kind of safety with callback based code, yes, you need to do that.

In most cases, logging uncaught exceptions and setting a timeout handler will do the job (http://vertx.io/docs/vertx-web/java/#_timeout_handler)

Otherwise, you may also use the Rxified API. The RxJava subscribers will be notified of any exception raised inside operations.

To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.

Hidwulf

unread,
Jul 25, 2017, 5:22:11 AM7/25/17
to vert.x
I will take a look at Rx thank you.
Reply all
Reply to author
Forward
0 new messages