1 |
|
2 |
|
3 |
|
4 | import { AuthErrorMessages, AuthErrorTypes } from './types';
|
5 | import { ConsoleLogger as Logger } from '@aws-amplify/core';
|
6 | import { AuthErrorStrings } from './common/AuthErrorStrings';
|
7 |
|
8 | const logger = new Logger('AuthError');
|
9 |
|
10 | export class AuthError extends Error {
|
11 | public log: string;
|
12 | constructor(type: AuthErrorTypes) {
|
13 | const { message, log } = authErrorMessages[type];
|
14 | super(message);
|
15 |
|
16 |
|
17 |
|
18 | this.constructor = AuthError;
|
19 | Object.setPrototypeOf(this, AuthError.prototype);
|
20 |
|
21 | this.name = 'AuthError';
|
22 | this.log = log || message;
|
23 |
|
24 | logger.error(this.log);
|
25 | }
|
26 | }
|
27 |
|
28 | export class NoUserPoolError extends AuthError {
|
29 | constructor(type: AuthErrorTypes) {
|
30 | super(type);
|
31 |
|
32 |
|
33 |
|
34 | this.constructor = NoUserPoolError;
|
35 | Object.setPrototypeOf(this, NoUserPoolError.prototype);
|
36 |
|
37 | this.name = 'NoUserPoolError';
|
38 | }
|
39 | }
|
40 |
|
41 | export const authErrorMessages: AuthErrorMessages = {
|
42 | noConfig: {
|
43 | message: AuthErrorStrings.DEFAULT_MSG,
|
44 | log: `
|
45 | Error: Amplify has not been configured correctly.
|
46 | This error is typically caused by one of the following scenarios:
|
47 |
|
48 | 1. Make sure you're passing the awsconfig object to Amplify.configure() in your app's entry point
|
49 | See https://aws-amplify.github.io/docs/js/authentication#configure-your-app for more information
|
50 |
|
51 | 2. There might be multiple conflicting versions of amplify packages in your node_modules.
|
52 | Refer to our docs site for help upgrading Amplify packages (https://docs.amplify.aws/lib/troubleshooting/upgrading/q/platform/js)
|
53 | `,
|
54 | },
|
55 | missingAuthConfig: {
|
56 | message: AuthErrorStrings.DEFAULT_MSG,
|
57 | log: `
|
58 | Error: Amplify has not been configured correctly.
|
59 | The configuration object is missing required auth properties.
|
60 | This error is typically caused by one of the following scenarios:
|
61 |
|
62 | 1. Did you run \`amplify push\` after adding auth via \`amplify add auth\`?
|
63 | See https://aws-amplify.github.io/docs/js/authentication#amplify-project-setup for more information
|
64 |
|
65 | 2. This could also be caused by multiple conflicting versions of amplify packages, see (https://docs.amplify.aws/lib/troubleshooting/upgrading/q/platform/js) for help upgrading Amplify packages.
|
66 | `,
|
67 | },
|
68 | emptyUsername: {
|
69 | message: AuthErrorStrings.EMPTY_USERNAME,
|
70 | },
|
71 |
|
72 | invalidUsername: {
|
73 | message: AuthErrorStrings.INVALID_USERNAME,
|
74 | },
|
75 | emptyPassword: {
|
76 | message: AuthErrorStrings.EMPTY_PASSWORD,
|
77 | },
|
78 | emptyCode: {
|
79 | message: AuthErrorStrings.EMPTY_CODE,
|
80 | },
|
81 | signUpError: {
|
82 | message: AuthErrorStrings.SIGN_UP_ERROR,
|
83 | log: 'The first parameter should either be non-null string or object',
|
84 | },
|
85 | noMFA: {
|
86 | message: AuthErrorStrings.NO_MFA,
|
87 | },
|
88 | invalidMFA: {
|
89 | message: AuthErrorStrings.INVALID_MFA,
|
90 | },
|
91 | emptyChallengeResponse: {
|
92 | message: AuthErrorStrings.EMPTY_CHALLENGE,
|
93 | },
|
94 | noUserSession: {
|
95 | message: AuthErrorStrings.NO_USER_SESSION,
|
96 | },
|
97 | deviceConfig: {
|
98 | message: AuthErrorStrings.DEVICE_CONFIG,
|
99 | },
|
100 | networkError: {
|
101 | message: AuthErrorStrings.NETWORK_ERROR,
|
102 | },
|
103 | autoSignInError: {
|
104 | message: AuthErrorStrings.AUTOSIGNIN_ERROR,
|
105 | },
|
106 | default: {
|
107 | message: AuthErrorStrings.DEFAULT_MSG,
|
108 | },
|
109 | };
|