Skip to content

Commit

Permalink
fix: return amplify user error as it is from AmplifyError.fromError (
Browse files Browse the repository at this point in the history
…#2288)

* fix: return amplify user error as it is from 'AmplifyError.fromError'

* PR Updates
  • Loading branch information
Amplifiyer authored Dec 2, 2024
1 parent ec4a7da commit cfdc854
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/five-comics-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@aws-amplify/platform-core': patch
---

return amplify user error as it is from `AmplifyError.fromError`
2 changes: 1 addition & 1 deletion packages/platform-core/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export abstract class AmplifyError<T extends string = string> 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<string>;
Expand Down
9 changes: 9 additions & 0 deletions packages/platform-core/src/errors/amplify_error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
15 changes: 5 additions & 10 deletions packages/platform-core/src/errors/amplify_error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,11 @@ export abstract class AmplifyError<T extends string = string> 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}`
Expand Down

0 comments on commit cfdc854

Please sign in to comment.