#Ignore global exception filter

1 messages · Page 1 of 1 (latest)

languid patrol
#

Hi, is it possible to ignore global exception filter? Let's say I have two filters, GraphQlExceptionFilter and HttpExceptionFilter, I need that GraphQlExceptionFilter to be global as my backend uses graphql as connection with frontend, but I also need some controllers which communicate with external services, both filters have same @Catch() to catch all errors and format them, GraphQL formats it to graphql errors, Http filters formats errors to exceptions that external service requires (some need statusCode, some status, some just code) and when I run http request to my REST endpoint GraphQlExceptionFilter comes in and throws GraphQLError and as it's initialized with { provide: APP_FILTER, useClass: GraphQlExceptionFilter } and all http filters are above the controller with @UseFilters(HttpExceptionFilter)

rocky patio
#

is it possible to ignore global exception filter?
no

#

unless another global exception filter caught your exception first, of course

languid patrol
#

currently my HttpFilter instead of returning status throws predefined exception, so I assume it goes like this
error -> HttpExceptionFilter -> GraphqlExceptionFilters catches error thrown by HttpExceptionFilter and converts it?

thick finch
#

Nope, once an exception is caught by a filter, it has to handle it. There is no hierarchy for re-thrown errors.

#

So an error goes to the default filter if and only if no other filter matches the exception class.

#

That's why you can't really have two global APP_FILTERs that handle the same exception class - only the first one would catch everything and the second nothing.

#

There's 2 options that you have:

#
  1. bind each filter individually to the corresponding controllers/resolvers