{"version":3,"file":"errorMaps.mjs","sources":["../../../../src/sync/processors/errorMaps.ts"],"sourcesContent":["import { resolveServiceErrorStatusCode } from '../utils';\nconst connectionTimeout = error => /^Connection failed: Connection Timeout/.test(error.message);\nconst serverError = error => resolveServiceErrorStatusCode(error) >= 500;\nexport const mutationErrorMap = {\n    BadModel: () => false,\n    BadRecord: error => {\n        const { message } = error;\n        return (/^Cannot return \\w+ for [\\w-_]+ type/.test(message) ||\n            /^Variable '.+' has coerced Null value for NonNull type/.test(message)); // newly required field, out of date client\n    },\n    ConfigError: () => false,\n    Transient: error => connectionTimeout(error) || serverError(error),\n    Unauthorized: error => error.message === 'Unauthorized' ||\n        resolveServiceErrorStatusCode(error) === 401,\n};\nexport const subscriptionErrorMap = {\n    BadModel: () => false,\n    BadRecord: () => false,\n    ConfigError: () => false,\n    Transient: observableError => {\n        const error = unwrapObservableError(observableError);\n        return connectionTimeout(error) || serverError(error);\n    },\n    Unauthorized: observableError => {\n        const error = unwrapObservableError(observableError);\n        return /Connection failed.+Unauthorized/.test(error.message);\n    },\n};\nexport const syncErrorMap = {\n    BadModel: () => false,\n    BadRecord: error => /^Cannot return \\w+ for [\\w-_]+ type/.test(error.message),\n    ConfigError: () => false,\n    Transient: error => connectionTimeout(error) || serverError(error),\n    Unauthorized: error => error.errorType === 'Unauthorized',\n};\n/**\n * Get the first error reason of an observable.\n * Allows for error maps to be easily applied to observable errors\n *\n * @param observableError an error from ZenObservable subscribe error callback\n */\nfunction unwrapObservableError(observableError) {\n    const { errors: [error], } = ({\n        // eslint-disable-next-line no-empty-pattern\n        errors: [],\n    } = observableError);\n    return error;\n}\nexport function getMutationErrorType(error) {\n    return mapErrorToType(mutationErrorMap, error);\n}\nexport function getSubscriptionErrorType(error) {\n    return mapErrorToType(subscriptionErrorMap, error);\n}\nexport function getSyncErrorType(error) {\n    return mapErrorToType(syncErrorMap, error);\n}\n/**\n * Categorizes an error with a broad error type, intended to make\n * customer error handling code simpler.\n * @param errorMap Error names and a list of patterns that indicate them (each pattern as a regex or function)\n * @param error The underying error to categorize.\n */\nexport function mapErrorToType(errorMap, error) {\n    const errorTypes = [...Object.keys(errorMap)];\n    for (const errorType of errorTypes) {\n        const matcher = errorMap[errorType];\n        if (matcher?.(error)) {\n            return errorType;\n        }\n    }\n    return 'Unknown';\n}\n"],"names":[],"mappings":";;AACA,MAAM,iBAAiB,GAAG,KAAK,IAAI,wCAAwC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;AAC/F,MAAM,WAAW,GAAG,KAAK,IAAI,6BAA6B,CAAC,KAAK,CAAC,IAAI,GAAG;AAC5D,MAAC,gBAAgB,GAAG;AAChC,IAAI,QAAQ,EAAE,MAAM,KAAK;AACzB,IAAI,SAAS,EAAE,KAAK,IAAI;AACxB,QAAQ,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK;AACjC,QAAQ,QAAQ,qCAAqC,CAAC,IAAI,CAAC,OAAO,CAAC;AACnE,YAAY,wDAAwD,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE;AACpF,IAAI,CAAC;AACL,IAAI,WAAW,EAAE,MAAM,KAAK;AAC5B,IAAI,SAAS,EAAE,KAAK,IAAI,iBAAiB,CAAC,KAAK,CAAC,IAAI,WAAW,CAAC,KAAK,CAAC;AACtE,IAAI,YAAY,EAAE,KAAK,IAAI,KAAK,CAAC,OAAO,KAAK,cAAc;AAC3D,QAAQ,6BAA6B,CAAC,KAAK,CAAC,KAAK,GAAG;AACpD;AACY,MAAC,oBAAoB,GAAG;AACpC,IAAI,QAAQ,EAAE,MAAM,KAAK;AACzB,IAAI,SAAS,EAAE,MAAM,KAAK;AAC1B,IAAI,WAAW,EAAE,MAAM,KAAK;AAC5B,IAAI,SAAS,EAAE,eAAe,IAAI;AAClC,QAAQ,MAAM,KAAK,GAAG,qBAAqB,CAAC,eAAe,CAAC;AAC5D,QAAQ,OAAO,iBAAiB,CAAC,KAAK,CAAC,IAAI,WAAW,CAAC,KAAK,CAAC;AAC7D,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