diff --git a/.changeset/five-comics-beg.md b/.changeset/five-comics-beg.md new file mode 100644 index 0000000000..10a4c35dd0 --- /dev/null +++ b/.changeset/five-comics-beg.md @@ -0,0 +1,5 @@ +--- +'@aws-amplify/platform-core': patch +--- + +return amplify user error as it is from `AmplifyError.fromError` diff --git a/packages/platform-core/API.md b/packages/platform-core/API.md index 55997c8747..f40d1c5364 100644 --- a/packages/platform-core/API.md +++ b/packages/platform-core/API.md @@ -33,7 +33,7 @@ export abstract class AmplifyError extends Error { // (undocumented) readonly details?: string; // (undocumented) - static fromError: (error: unknown) => AmplifyError<'UnknownFault' | 'CredentialsError' | 'InsufficientDiskSpaceError' | 'InvalidCommandInputError' | 'DomainNotFoundError' | 'SyntaxError'>; + static fromError: (error: unknown) => AmplifyError; // (undocumented) static fromStderr: (_stderr: string) => AmplifyError | undefined; static isAmplifyError: (error: unknown) => error is AmplifyError; diff --git a/packages/platform-core/src/errors/amplify_error.test.ts b/packages/platform-core/src/errors/amplify_error.test.ts index 94980ab213..c4f0c974f4 100644 --- a/packages/platform-core/src/errors/amplify_error.test.ts +++ b/packages/platform-core/src/errors/amplify_error.test.ts @@ -205,4 +205,13 @@ void describe('AmplifyError.fromError', async () => { ); }); }); + void it('return amplify user errors as it is', () => { + const error = new AmplifyUserError('DeploymentInProgressError', { + message: 'Deployment already in progress', + resolution: 'wait for it', + }); + const actual = AmplifyError.fromError(error); + assert.deepStrictEqual(error, actual); + assert.strictEqual(actual.resolution, error.resolution); + }); }); diff --git a/packages/platform-core/src/errors/amplify_error.ts b/packages/platform-core/src/errors/amplify_error.ts index 9ea73c8ff1..314444252e 100644 --- a/packages/platform-core/src/errors/amplify_error.ts +++ b/packages/platform-core/src/errors/amplify_error.ts @@ -118,16 +118,11 @@ export abstract class AmplifyError extends Error { ); }; - static fromError = ( - error: unknown - ): AmplifyError< - | 'UnknownFault' - | 'CredentialsError' - | 'InsufficientDiskSpaceError' - | 'InvalidCommandInputError' - | 'DomainNotFoundError' - | 'SyntaxError' - > => { + static fromError = (error: unknown): AmplifyError => { + if (AmplifyError.isAmplifyError(error)) { + return error; + } + const errorMessage = error instanceof Error ? `${error.name}: ${error.message}`