Skip to content

Commit cfdc854

Browse files
authored
fix: return amplify user error as it is from AmplifyError.fromError (#2288)
* fix: return amplify user error as it is from 'AmplifyError.fromError' * PR Updates
1 parent ec4a7da commit cfdc854

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

.changeset/five-comics-beg.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aws-amplify/platform-core': patch
3+
---
4+
5+
return amplify user error as it is from `AmplifyError.fromError`

packages/platform-core/API.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export abstract class AmplifyError<T extends string = string> extends Error {
3333
// (undocumented)
3434
readonly details?: string;
3535
// (undocumented)
36-
static fromError: (error: unknown) => AmplifyError<'UnknownFault' | 'CredentialsError' | 'InsufficientDiskSpaceError' | 'InvalidCommandInputError' | 'DomainNotFoundError' | 'SyntaxError'>;
36+
static fromError: (error: unknown) => AmplifyError;
3737
// (undocumented)
3838
static fromStderr: (_stderr: string) => AmplifyError | undefined;
3939
static isAmplifyError: (error: unknown) => error is AmplifyError<string>;

packages/platform-core/src/errors/amplify_error.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,13 @@ void describe('AmplifyError.fromError', async () => {
205205
);
206206
});
207207
});
208+
void it('return amplify user errors as it is', () => {
209+
const error = new AmplifyUserError('DeploymentInProgressError', {
210+
message: 'Deployment already in progress',
211+
resolution: 'wait for it',
212+
});
213+
const actual = AmplifyError.fromError(error);
214+
assert.deepStrictEqual(error, actual);
215+
assert.strictEqual(actual.resolution, error.resolution);
216+
});
208217
});

packages/platform-core/src/errors/amplify_error.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,11 @@ export abstract class AmplifyError<T extends string = string> extends Error {
118118
);
119119
};
120120

121-
static fromError = (
122-
error: unknown
123-
): AmplifyError<
124-
| 'UnknownFault'
125-
| 'CredentialsError'
126-
| 'InsufficientDiskSpaceError'
127-
| 'InvalidCommandInputError'
128-
| 'DomainNotFoundError'
129-
| 'SyntaxError'
130-
> => {
121+
static fromError = (error: unknown): AmplifyError => {
122+
if (AmplifyError.isAmplifyError(error)) {
123+
return error;
124+
}
125+
131126
const errorMessage =
132127
error instanceof Error
133128
? `${error.name}: ${error.message}`

0 commit comments

Comments
 (0)