-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(auth): throw extended AuthError for service errors from user pool & id pool #14230
feat(auth): throw extended AuthError for service errors from user pool & id pool #14230
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The diff is messy but I only added the 1st test case.
...(statusCode === 404 | ||
? { | ||
recoverySuggestion: | ||
'Please add the object with this key to the bucket as the key is not found.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: What's the error.message
for 404 error? Do we actually need to provide a recovery suggestion for 404 errors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We actually to need it because the Storage.getProperties
's HEAD request does not return a payload. So in that case we won't have any message other than recoverySuggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But since we already have special handling of the error name for 404(setting name to NotFound
), this is indeed unnecessary. I will remove it in the next PR where I put all the changes to the Storage category
}: AmplifyErrorParams) { | ||
super(message); | ||
|
||
this.name = name; | ||
this.underlyingError = underlyingError; | ||
this.recoverySuggestion = recoverySuggestion; | ||
if (underlyingError) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: why do we need this extra guard, underlyingError
and recoverySuggestion
are supposed to be optional (undefined is allowed above 😅)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HuiSF It's very minor difference. If we always set these properties, we might as well just model these properties like readonly recoverySuggestion: string | undefined;
this.metadata = { | ||
...(metadata.extendedRequestId | ||
? { extendedRequestId: metadata.extendedRequestId } | ||
: {}), | ||
...(metadata.httpStatusCode | ||
? { httpStatusCode: metadata.httpStatusCode } | ||
: {}), | ||
...(metadata.requestId ? { requestId: metadata.requestId } : {}), | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can be simplified as the following, as ResponseMetadata
allows there properties to contain undefined
as values?
const { extendedRequestId, httpStatusCode, httpStatusCode } = metadata;
this.metadata = {
extendedRequestId,
httpStatusCode,
httpStatusCode,
};
e69f680
to
eb08d00
Compare
I have to bump up the bundle size limit in a lot of packages for a little, because the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
expect(deserializer(response as any)).rejects.toThrow( | ||
new AuthError({ | ||
try { | ||
await deserializer(response as any); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use expect().rejects.toThrow()
instead to ensure the assertions in the catch block actually happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toThrow()
does not verify the non-message part of the error instance. See line 37, I made sure the assertion actually runs with expect.assertions()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense 👍
7af353b
into
aws-amplify:feat/monitoring-instrument/main
Description of changes
metadata
property to the baseAmplifyError
class. So customers can inspect the requestId if anAuthError
is caused by a service error response.GetId
,GetCredentialsForId
) to throw AuthError. Previously, the 2 APIs throw the baseError
instance.$metadata
from custom clients tometadata
of theAmplifyError
/AuthError
.AuthError
.Issue #, if available
Description of how you validated changes
Unit tests
Checklist
yarn test
passesChecklist for repo maintainers
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.