Should a jax-rs based framework use a single exception mapper?

Viewed 269

We have a large legacy application to which we recently added jersey/jax-rs based functionality. The idea is that we will implement new functionality for our UI layer as restful APIs. A first prototype is working nicely - but it is lacking proper error handling.

I had a closer look at the initial implementation, and what I found is that there is a "base task" class that registers a specific ExceptionMapper. The idea is that there will be different and disjunct sub tasks extending that base task.

My initial thought was: each sub task should have its own, specific exception mapper.

In other words: I see two different options:

  • one central exception mapper, that works all exceptions thrown within any of the numerous sub tasks we are going to implement over time
  • one mapper per sub task

Option 1 leading to well, one central piece of code - but much less flexible compared to option 2 (it starts with things like: normally our sub tasks have their own "log id" when writing logs - but a central mapper doesn't know about its context and has to use the very same log id all the time).

My question is: are the hard technical facts (or well established "best procedures") to select between the two options?

2 Answers
Related