Skip to content

Exception filters do not catch errors for subscriptions #249

@dantman

Description

@dantman

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Expected behavior

Exception filters should catch errors in subscriptions and allow filtering.

Current behavior

Exception filters catch errors thrown in http resolvers/mutations and the error Apollo reports can be replaced. But for subscriptions the catch of an exception filter is not called and the thrown error goes directly to Apollo and cannot be replaced.

Minimal reproduction of the problem with instructions

  • Setup NestJS with GraphQL
  • Setup subscriptions according to the manual
  • Add a subscription to a resolver that throws an error
  • Implement a exception filter and add a @UseFilters for it to the resolver class
  • Test it out / debug it, the exception filter will not be called

What is the motivation / use case for changing the behavior?

GraphQL and HTTP API calls use completely different error types. I'd like to throw custom general errors from my services e.g. AuthorizationTokenFailure, EntityDoesNotExist, etc... and convert them to a Http error or an Apollo error depending on the context. However this does not work if exception filters work in resolvers/mutations but not GraphQL subscriptions.

Environment


Nest version: 6.2.0, @nestjs/graphql@6.2.0-next.5
 
For Tooling issues:
- Node version: v12.1.0
- Platform: Mac

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions