Skip to content
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

apollo-server-core formatError never called #1439

Closed
ak99372 opened this issue Jul 27, 2018 · 3 comments
Closed

apollo-server-core formatError never called #1439

ak99372 opened this issue Jul 27, 2018 · 3 comments
Labels
🌹 has-reproduction ❤ Has a reproduction in Glitch, CodeSandbox or Git repository.

Comments

@ak99372
Copy link

ak99372 commented Jul 27, 2018

We're using [runHttpQuery] from apollo-server-core on lambda and passing formatError as one of the options.
However this handler never gets called back when exception is raised in resolver...

resolve = (source, args, context, info) => { throw new Error("This is generic error"); }

Is this meant for other types of errors?

Notes: I had a look at runHttpQuery which passes the formatError to runQuery but it looks like runQuery never uses this handler (I'm also using [formatResponse] which gets called without issues)

@ghost ghost added the 🌹 has-reproduction ❤ Has a reproduction in Glitch, CodeSandbox or Git repository. label Jul 27, 2018
@ak99372 ak99372 changed the title apollo-server-core formatError apollo-server-core formatError never called Jul 27, 2018
@ghost ghost added the 🌹 has-reproduction ❤ Has a reproduction in Glitch, CodeSandbox or Git repository. label Jul 27, 2018
@robrichard
Copy link
Contributor

I've been looking into this more and I can see that formatError is called only when passed to the ApolloServer constructor (via https://github.com/apollographql/apollo-server/blob/master/packages/apollo-server-core/src/formatters.ts#L22)

It is ignored when you use runHttpQuery or runQuery directly.

Unfortunately you cannot access the express req object in formatError when you pass it to the ApolloServer constructor.

@tgriesser
Copy link
Contributor

Just opened a PR to fix this in #1662

@abernix
Copy link
Member

abernix commented Jul 4, 2019

I'll close this for the reasons I explained in #1662 (comment).

The formatError method aligns with the underlying graphql-js's formatError which doesn't have access to the context either. If you're looking to access the context and errors at the same time, check out the #2719 hook, which would allow you to augment an error with additional properties, based on the requestContext (which didEncounterErrors does receive!) and respond accordingly in formatError. (You could also just manipulate the error within the didEncounterErrors bit, but your usage may vary.)

@abernix abernix closed this as completed Jul 4, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🌹 has-reproduction ❤ Has a reproduction in Glitch, CodeSandbox or Git repository.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants