{"version":3,"file":"repackageAuthError.mjs","sources":["../../../../src/utils/errors/repackageAuthError.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n/**\n * Checks to see if the given response or subscription message contains an\n * Unauthorized error. If it does, it changes the error message to include instructions\n * for the app developer.\n */\nexport function repackageUnauthorizedError(content) {\n    if (content.errors && Array.isArray(content.errors)) {\n        content.errors.forEach(e => {\n            if (isUnauthorizedError(e)) {\n                e.message = 'Unauthorized';\n                e.recoverySuggestion =\n                    `If you're calling an Amplify-generated API, make sure ` +\n                        `to set the \"authMode\" in generateClient({ authMode: '...' }) to the backend authorization ` +\n                        `rule's auth provider ('apiKey', 'userPool', 'iam', 'oidc', 'lambda')`;\n            }\n        });\n    }\n    return content;\n}\nfunction isUnauthorizedError(error) {\n    // Error pattern corresponding to appsync calls\n    if (error?.originalError?.name?.startsWith('UnauthorizedException')) {\n        return true;\n    }\n    // Error pattern corresponding to appsync subscriptions\n    if (error.message?.startsWith('Connection failed:') &&\n        error.message?.includes('Permission denied')) {\n        return true;\n    }\n    return false;\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,0BAA0B,CAAC,OAAO,EAAE;AACpD,IAAI,IAAI,OAAO,CAAC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;AACzD,QAAQ,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI;AACpC,YAAY,IAAI,mBAAmB,CAAC,CAAC,CAAC,EAAE;AACxC,gBAAgB,CAAC,CAAC,OAAO,GAAG,cAAc;AAC1C,gBAAgB,CAAC,CAAC,kBAAkB;AACpC,oBAAoB,CAAC,sDAAsD,CAAC;AAC5E,wBAAwB,CAAC,0FAA0F,CAAC;AACpH,wBAAwB,CAAC,oEAAoE,CAAC;AAC9F,YAAY;AACZ,QAAQ,CAAC,CAAC;AACV,IAAI;AACJ,IAAI,OAAO,OAAO;AAClB;AACA,SAAS,mBAAmB,CAAC,KAAK,EAAE;AACpC;AACA,IAAI,IAAI,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,UAAU,CAAC,uBAAuB,CAAC,EAAE;AACzE,QAAQ,OAAO,IAAI;AACnB,IAAI;AACJ;AACA,IAAI,IAAI,KAAK,CAAC,OAAO,EAAE,UAAU,CAAC,oBAAoB,CAAC;AACvD,QAAQ,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,mBAAmB,CAAC,EAAE;AACtD,QAAQ,OAAO,IAAI;AACnB,IAAI;AACJ,IAAI,OAAO,KAAK;AAChB;;;;"}