UNPKG

1.24 kBJavaScriptView Raw
1import { global } from "../utilities/globals/index.js";
2import { ApolloErrorMessageHandler } from "../utilities/globals/invariantWrappers.js";
3import { setErrorMessageHandler } from "./setErrorMessageHandler.js";
4/**
5 * Injects Apollo Client's default error message handler into the application and
6 * also loads the error codes that are passed in as arguments.
7 */
8export function loadErrorMessageHandler() {
9 var errorCodes = [];
10 for (var _i = 0; _i < arguments.length; _i++) {
11 errorCodes[_i] = arguments[_i];
12 }
13 setErrorMessageHandler(handler);
14 for (var _a = 0, errorCodes_1 = errorCodes; _a < errorCodes_1.length; _a++) {
15 var codes = errorCodes_1[_a];
16 Object.assign(handler, codes);
17 }
18 return handler;
19}
20var handler = (function (message, args) {
21 if (typeof message === "number") {
22 var definition = global[ApolloErrorMessageHandler][message];
23 if (!message || !(definition === null || definition === void 0 ? void 0 : definition.message))
24 return;
25 message = definition.message;
26 }
27 return args.reduce(function (msg, arg) { return msg.replace(/%[sdfo]/, String(arg)); }, String(message));
28});
29//# sourceMappingURL=loadErrorMessageHandler.js.map
\No newline at end of file