node.js – NestJS : How to bubble up/propagate exception?

In NestJS, we can had Exceptions to route or to specific module using @UseFilters() or to the whole application using useGlobalFilters().

So, how can I bubble up/propagate the route or module level caught exception to the global exception filter ?

For example, AuthExceptionFilter is attached to the Users’ controller and there’s a global exception filter called HttpExceptionFilter.

In specific scenario, for instance, when auth exception’s message is “X”, I want this specific error to be bubbled up / propagated to the global exception filter (HttpExceptionFilter), so that it knows how to handle it.

Or in another case, I just want to add few properties to the exception from AuthExceptionFilter before letting it handled by HttpExceptionFilter.

so, basically I want to bubble up or propagate or rethrow error caught in specific exception filter to global(generic) exception filter.

Read more here: Source link