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

Log GraphQLErrors automatically #1690

Merged
merged 13 commits into from
Feb 6, 2024
Merged

Log GraphQLErrors automatically #1690

merged 13 commits into from
Feb 6, 2024

Conversation

frandiox
Copy link
Contributor

@frandiox frandiox commented Jan 26, 2024

The new errors returned in const {data, errors} = await storefront.query(...) are likely to be missed because they are not breaking the flow.

This PR adds an auto-logger for this type of error and enhances it with the query name.


Aside from that, I realized we were not showing the GraphiQL link anymore for this kind of error. This is fixed now:

image

@frandiox frandiox requested review from blittle and a team January 26, 2024 06:16

This comment has been minimized.

@wizardlyhel
Copy link
Contributor

wizardlyhel commented Feb 1, 2024

Could we make logError a callback function (error?: GraphQLError) => boolean? Our default would be just () => true

I have been thinking how we can extend the ability of selectively suppressing errors to developers instead of just all console log or not. We do have a case of cart query returning graphql errors that can be safely ignored.

(edit) I made the boolean function passing back single error after looking at your code. So it would be just

result.errors.forEach((error: Error) => {
  if (error) {
    error.stack = getSyncStack(error.message, error.name);
      if (logErrors(error)) console.error(error);
   }
 });

@wizardlyhel
Copy link
Contributor

like this #1729

@frandiox
Copy link
Contributor Author

frandiox commented Feb 6, 2024

@wizardlyhel What about boolean | ((error: Error) => boolean)? I can revert it if it's no good 👍

@wizardlyhel wizardlyhel merged commit eee5d92 into main Feb 6, 2024
10 checks passed
@wizardlyhel wizardlyhel deleted the fd-log-gqlerrors branch February 6, 2024 20:35
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

Successfully merging this pull request may close these issues.

2 participants