Reconsider exception-handlers
See original GitHub issueCurrently, Javalin will only run the closest matching exception handler. From the docs:
app.exception(NullPointerException.class, (e, ctx) -> {
// handle nullpointers here
});
app.exception(Exception.class, (e, ctx) -> {
// handle general exceptions here
// will not trigger if more specific exception-mapper found
});
This could be a bit annoying to deal with, especially when developing plugins (as pointed out by @jkschneider in https://github.com/tipsy/javalin/pull/959)
Should multiple exception handlers be allowed to run per exception?
Should we have something like next()
/done()
?
This would be a breaking change, but I guess we could also make it configurable.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Reconsider exception handling concept · Issue #35 · zalando/riptide ...
the general idea should be: pass through everything as-is from custom callbacks/mappers as well as from the underlying RestTemplate; the only case I...
Read more >Reconsider Flow Error Handling | IdeaExchange
Now the idea: Improve your code to do a null check on Error Id before sending the Exception Email. If an error occured...
Read more >MOTIONS TO REOPEN OR RECONSIDER
Exception for In Absentia Removal or Deportation. The filing of a motion to reopen an in absentia order of deportation or removal stays...
Read more >Parliamentary procedure: What is a motion to reconsider?
To properly handle a motion to reconsider, a member who voted on the prevailing side is recognized by the chair and moves to...
Read more >Chapter 5 - Appeals, Motions to Reopen, and Motions ... - USCIS
If the appeal relates to a revocation of an approved special immigrant juvenile (SIJ) petition, the appeal must be filed within 15 calendar...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For the projects we’ve done we’ve always handled multiple expected exceptions that parse the exception into a specific response and status, and one that is a fall back in case no better exception would be handled (which turns into a 500, sorry something went wrong).
It seems reasonable to think most of these handlers would be handled separately, I would have been very surprised if multiple handlers were called when a specific exception (like Unauthorized) was called. Especially if some of those were expensive. The way I’ve been looking at the exception handlers are: An exception ocurred, decide what response should be sent to the client. It doesn’t really make sense to ask multiple functions what response should be provided, but maybe I’m thinking about them differently than others do?
Maybe it would be easier to have a separate function for registering handlers that should run on all exceptions? Something like
app.notifyOnException(Exception.class, (e, ctx) ->{})
?There are probably cases to suggest this should work both ways. From my perspective as a metrics instrumentation library author, I would prefer listeners to be called after anything that currently implements
exception(..)
. Specifically, this is because my listener would be completing a timing operation on a REST endpoint, and I want to be able to tag this telemetry with the HTTP status code, which can be influenced by a traditional exception handler.