Skip to content

Request: Global Error Handler #773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
thanpolas opened this issue Mar 30, 2017 · 2 comments
Closed

Request: Global Error Handler #773

thanpolas opened this issue Mar 30, 2017 · 2 comments

Comments

@thanpolas
Copy link

Hello,

We want to enforce a global error handler across all our graphql mutations and queries so as to apply specific business logic before the error reaches the client.

So far I have only come up with the kadirahq/graphql-errors package, which basically walks all the fields of all the type definitions and wraps the resolve method of each one.

Is that what we only have today? Am I missing something? Would you consider adding such a feature, a global error handler?

@baer
Copy link
Contributor

baer commented May 26, 2017

There are a couple of issues on this project to explore different error handling. See #284 #402

I'm not completely sure what types of business logic you're talking about applying but the formatError option in express-graphql will catch and aggregate errors thrown during resolution. You can use that function to log or format before they reach the client.

@leebyron
Copy link
Contributor

This is already possible! Thanks @baer for some pointers to how you can implement this.

Since this package does not deal with sending results to a client, then the expectation is that you would place any post-processing between the output of any calls to this package and before serializing and sending to a client.

For example, in express-graphql, as @baer explained, a global error handler can be provided as an option - here is how that ends up being used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants