-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
release(required): network error has not been properly detected (#13935)
* fix(core): retry is not applied on network error * fix(auth): wrongly clear tokens on network error when refresh tokens * chore(aws-amplify): bump list bundle size limits
- Loading branch information
Showing
5 changed files
with
70 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/core/__tests__/clients/middleware/retry/defaultRetryDecider.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { HttpResponse } from '../../../../src/clients'; | ||
import { getRetryDecider } from '../../../../src/clients/middleware/retry/defaultRetryDecider'; | ||
import { AmplifyError } from '../../../../src/errors'; | ||
import { AmplifyErrorCode } from '../../../../src/types'; | ||
|
||
describe('getRetryDecider', () => { | ||
const mockErrorParser = jest.fn(); | ||
|
||
describe('created retryDecider', () => { | ||
const mockNetworkErrorThrownFromFetch = new AmplifyError({ | ||
name: AmplifyErrorCode.NetworkError, | ||
message: 'Network Error', | ||
}); | ||
const mockNetworkErrorThrownFromXHRInStorage = new Error('Network Error'); | ||
mockNetworkErrorThrownFromXHRInStorage.name = 'ERR_NETWORK'; | ||
mockNetworkErrorThrownFromXHRInStorage.message = 'Network Error'; | ||
|
||
test.each([ | ||
[ | ||
'a network error from the fetch handler', | ||
true, | ||
mockNetworkErrorThrownFromFetch, | ||
], | ||
[ | ||
'a network error from the XHR handler defined in Storage', | ||
true, | ||
mockNetworkErrorThrownFromXHRInStorage, | ||
], | ||
])('when receives %p returns %p', (_, expected, error) => { | ||
const mockResponse = {} as unknown as HttpResponse; | ||
mockErrorParser.mockReturnValueOnce(error); | ||
const retryDecider = getRetryDecider(mockErrorParser); | ||
|
||
expect(retryDecider(mockResponse, error)).resolves.toBe(expected); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters