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

Mask Error will always log an "Error Log". #3124

Open
JoJ123 opened this issue Dec 1, 2023 · 1 comment
Open

Mask Error will always log an "Error Log". #3124

JoJ123 opened this issue Dec 1, 2023 · 1 comment

Comments

@JoJ123
Copy link
Contributor

JoJ123 commented Dec 1, 2023

Describe the bug

When we use maskError to modify the error that we want to return to the client, it will always throw an error to the log.
Probably this change was introduced with this PR:
#2084

The idea is, that the maskError (earlier versions of GraphQLYoga called formatError) will format the error and based on a flag of our CustomError class (warning/error) we could on our own decide if we want to log an error or a warning.

Can this default logger.error be optional?

Your Example Website or App

GitHub
SandBox

Steps to Reproduce the Bug or Issue

Use MaskedError

Expected behavior

No Default Error Log

Screenshots or Videos

No response

Platform

GraphqlYoga 5.0.1

Additional context

No response

@klippx
Copy link
Contributor

klippx commented Dec 6, 2023

I agree, I am also annoyed by this logger which is on by default, and it is very hard to find the source since it has no prefix. We throw GraphQLWarnings which is a special error that we don't care about but this logger seems to log it any way with no possibility to opt out of it (?).

I would propose to change this type of usages:

this.logger.error(error)

to

errorCb(error) // or use event emitter

where errorCb or whatever you call it can be a config option that by default is

errorCb = (error: unknown) => {
  logger.error("Yoga error", { error: error instanceof Error ? error.message : error })
}

So we at least can opt out of spamming this in prod / staging envs without turning off Yoga logger completely, and also making it easier to find where the error is coming from in the source code.

@n1ru4l n1ru4l added good first issue help wanted Extra attention is needed and removed good first issue help wanted Extra attention is needed labels Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants