Hi,
I am trying to figure out a way to have a global exception handler. The idea behind this is to have one spot to catch all exceptions so that we can log them and also send them up to rollbar. In spring there is the @ControllerAdvice that we can use to make sure any web request errors get tracked. However, this does not cover errors thrown in camunda tasks (for example, in a java delegate).
One solution I have is using the camunda-bpm-reactor event bus to register a consumer for the throwable class. Unfortunately with the way that the default error handler always rethrows exceptions and the fact that it is always registered first in the event bus, no other listeners for throwable ever get called. What I have managed to do is unregister all throwable consumers, register my consumer (so it is first in line), then re-register the ones I previously unregistered. You can see this in the snippet of code below.
val registeredConsumers = eventBus.consumerRegistry.select(Throwable::class.java) val unregistered = eventBus.consumerRegistry.unregister(Throwable::class.java) eventBus.on(ClassSelector(Throwable::class.java), { ev: Event<Throwable> -> println(ev.data.toString()) }) if (unregistered && registeredConsumers.isNotEmpty()) { registeredConsumers.forEach { eventBus.on(it.selector, it.`object`) } }
Has anyone encountered this problem before and have a better way of solving it? Is there a way to register a default error handler with camunda-bpm-reactor that takes precedence over the default handler? Is there another plugin that I could use or a feature of camunda I am missing?