UNPKG

1.81 kBTypeScriptView Raw
1/**
2 * The error message handler is a function that is called when a message is
3 * logged or an error is thrown to determine the contents of the error message
4 * to be logged or thrown.
5 */
6export type ErrorMessageHandler = {
7 /**
8 * @param message - Usually the error message number (as defined in
9 * `@apollo/client/invariantErrorCodes.js`).
10 * In some edge cases, this can already be a string, that can be passed through
11 * as an error message.
12 *
13 * @param args - The placeholders that can be passed into the error message (pre-stringified).
14 * These relate with the `%s` and `%d` [substitution strings](https://developer.mozilla.org/en-US/docs/Web/API/console#using_string_substitutions)
15 * in the error message defined in `@apollo/client/invariantErrorCodes.js`.
16 *
17 * ⚠️ Note that arguments will only be passed in for error messages.
18 * For normal log messages, you will get an empty array here and they will directly
19 * be passed to `console.log` instead, to have the string subsitution done by the
20 * engine, as that allows for nicer (and in the case of a browser, interactive)
21 * output.
22 *
23 * @returns The error message to be logged or thrown. If it returns `undefined`,
24 * the mechanism will fall back to the default:
25 * A link to https://go.apollo.dev/c/err with Apollo Client version,
26 * the error message number, and the error message arguments encoded into
27 * the URL hash.
28 */ (message: string | number, args: string[]): string | undefined;
29};
30/**
31 * Overrides the global "Error Message Handler" with a custom implementation.
32 */
33export declare function setErrorMessageHandler(handler: ErrorMessageHandler): void;
34//# sourceMappingURL=setErrorMessageHandler.d.ts.map
\No newline at end of file