-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
expose setErrorMessageHandler
#11694
Conversation
🦋 Changeset detectedLatest commit: 5bc6188 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
if (!global[ApolloErrorMessageHandler]) { | ||
global[ApolloErrorMessageHandler] = handler as typeof handler & ErrorCodes; | ||
} | ||
setErrorMessageHandler(handler as typeof handler & ErrorCodes); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a notable change (but probably not very relevant):
If a user had created their own handler, and then called loadErrorMessageHandler
, previously that would not have overwritten that handler, and now it would.
We have never exposed a way of setting that handler before, though, so it probably doesn't matter.
size-limit report 📦
|
(msg, arg) => msg.replace(/%[sdfo]/, String(arg)), | ||
String(message) | ||
); | ||
const handler = ((message: string | number, args: unknown[]) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another thing to note is that this is now on module level, so anything that has loaded into it with loadErrorMessageHandler
will now stay inside of it, and it cannot just be reset by delete global[ApolloErrorMessageHandler]
- this might bite us in our tests, (let's see), but probably nobody else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dig it. Thanks for getting this up so quick!
✅ Deploy Preview for apollo-client-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for apollo-client-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
@iiroj Mentioning so you see this - it will give you full control over error messages and log messages. This might, in the case of On top of that, you can control the logging of that using |
@phryneas Thanks! I'm pretty sure this would allow me to override the message by supplying something like: setErrorMessageHandler(() => "") However, all of the code in the getHandledErrorMsg(message, optionalParams) || getFallbackErrorMsg(message, optionalParams) Also, since in the I would expect
|
@iiroj I have documented both of these behaviours in the /**
* @returns The error message to be logged or thrown. If it returns `undefined`,
* the mechanism will fall back to the default:
* A link to https://go.apollo.dev/c/err with Apollo Client version,
* the error message number, and the error message arguments encoded into
* the URL hash.
*/ => Returning /**
* ⚠️ Note that arguments will only be passed in for error messages.
* For normal log messages, you will get an empty array here and they will directly
* be passed to `console.log` instead, to have the string subsitution done by the
* engine, as that allows for nicer (and in the case of a browser, interactive)
* output.
*/ This is something that's also kind of a tradeoff: That said, (Take a look at the packaged JavaScript - a call to In a production build, you'll only see If you even want to silence those logs in a development environment, completely (although I'd really recommend logging something!) you can still use |
This would be an alternative solution to the concerns brought up in #11667 and #11655.