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

using async in formatError hook, error message will be no complete #1747

Closed
anymost opened this issue Sep 29, 2018 · 4 comments
Closed

using async in formatError hook, error message will be no complete #1747

anymost opened this issue Sep 29, 2018 · 4 comments

Comments

@anymost
Copy link

anymost commented Sep 29, 2018

when I use async function in formatError hook, for example:
formatError:async (error) => { // some other async code console.log(error); return error; }
the error message sent to client don't contain error detail, just like this:
{ "data":null, "errors":[{}] }
if I remove async , the error message sent to client will be complete, wish some body help me, thanks a lot

@anymost anymost changed the title using async in formatError hook, using async in formatError hook, error message will be no complete Sep 29, 2018
@anymost
Copy link
Author

anymost commented Sep 29, 2018

I found calling the formatError function without async when I searched the source code, the code position is :

export function formatApolloErrors(

@eltonio450 eltonio450 mentioned this issue Dec 10, 2018
4 tasks
@cheapsteak cheapsteak added the 🚧👷‍♀️👷‍♂️🚧 in triage Issue currently being triaged label Jul 8, 2019
@cheapsteak
Copy link
Member

Hi there
Closing this issue because formatError does not support async functions
Curious if you could share your use-case? Perhaps you might benefit from the didEncounterErrors lifecycle that was recently added - #2719

@abernix abernix removed 🚧👷‍♀️👷‍♂️🚧 in triage Issue currently being triaged labels Jul 9, 2019
@marlonfsolis
Copy link

marlonfsolis commented Feb 28, 2023

Hi @cheapsteak,
Do you think is a valid scenario call an async method that log the error on a DB?
I think would be simpler than inplement didEncounterErrors. But I am not sure how hard would be to convert formatError to async function.
It was very hard to find out how to implement didEncounterErrors. The documentation does not provide a good example of how to implement this event lifecycle.
The formatError is more intuitive and simpler.

const formatError = async (formattedError:GraphQLFormattedError, error:unknown): GraphQLFormattedError => 
{
   const errorLogId = await logError(LogLevel.ERROR, formattedError.message);
   formattedError.message =+ ` - ErrorNo.: ${errorLogId }`;
   return formattedError;
}

@trevor-scheer
Copy link
Member

@marlonfsolis didEncounterErrors is the correct approach for async logging. It looks like we have some examples for other hooks but not this one. TypeScript also makes working with our libraries easier. Tests are often a good place to look for examples (there are a few in our repo).

Here's the skeleton of a plugin which implements didEncounterErrors. Hope you find this helpful.

plugins: [{
  async requestDidStart() {
    return {
      async didEncounterErrors(requestContext) {
        // log to service
      }
    };
  } 
}]

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants