Is there any way to set an global exception handler for HTTP server

45 views
Skip to first unread message

Han He

unread,
Aug 22, 2017, 3:52:20 AM8/22/17
to vert.x
I want to return a server error (503) to client side when there is an exception raised inside the request handler. Currently I got the following error message in the log. And client side wait a long time to timeout..
2017-08-22 15:20:19  [ vert.x-eventloop-thread-5:32930 ] - [ ERROR ]
  Unhandled exception
java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to java.lang.CharSequence

 I googled, and found the failureHandler, but it was not called when the exception raised. The exception is thrown inside a result callback of a mongodb query when parsing the JsonObject.

Just wondering if there is an exception handler for this situation so we can return a server error to client instead of making client waiting for a long timeout.

Thanks,
Han

Julien Viet

unread,
Aug 22, 2017, 9:42:27 AM8/22/17
to ve...@googlegroups.com
Hi,

you can set an exception handler on the Context of the Verticle that will raise any uncaught exception in this context.

Julien

--
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.
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/381e8507-6a99-4426-be43-094c26819e48%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Han He

unread,
Aug 23, 2017, 4:18:22 AM8/23/17
to vert.x
Thanks a lot for your advice. It worked. I managed to set the exception handler for the context which handles the http request and then return a server error to client. 
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages