-
Notifications
You must be signed in to change notification settings - Fork 8
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
Supports [email protected] #165
Merged
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
770218d
build(deps): bump axios from 0.27.2 to 1.6.0
dependabot[bot] 728ba11
feat: supports [email protected]
1b58338
feat: stops support node v14
20c701b
fix: pass all unit tests
c042dae
fix: supports node v14
642b298
feat!: fix types to support [email protected]
06b3b0d
fix: adjust type naming
shawnzhu f9a58ed
fix: improves type
shawnzhu 0690f50
fix: improves type from feedback
shawnzhu 0bf1586
fix: reuses redeclared types
shawnzhu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import isBoolean from 'lodash/isBoolean'; | ||
import defaults from 'lodash/defaults'; | ||
import _get from 'lodash/get'; | ||
import _inRange from 'lodash/inRange'; | ||
import { RequestError } from './helpers/requestError'; | ||
import type { AlphaOptions } from '../types'; | ||
import type { Alpha } from '../alpha'; | ||
import { AxiosError } from 'axios'; | ||
|
||
export interface RetryOptions { | ||
attempts: number; | ||
|
@@ -17,11 +18,20 @@ export interface RetryAlphaOptions extends Omit<AlphaOptions, 'retry'> { | |
retry: RetryOptions; | ||
} | ||
|
||
const isRetryableError = (error: any | RequestError) => { | ||
const isServerSideError = (error: RequestError) => { | ||
return ( | ||
error.response | ||
&& ( | ||
_inRange(_get(error.response, 'StatusCode', 0) as number, 500, 600) | ||
|| _inRange(_get(error.response, 'status', 0) as number, 500, 600) | ||
) | ||
); | ||
}; | ||
|
||
const isRetryableError = (error: RequestError) => { | ||
if (error.isLambdaInvokeTimeout) return true; | ||
|
||
return error.code !== 'ECONNABORTED' && | ||
(!error.response || (error.response.status >= 500 && error.response.status <= 599)); | ||
return error.code !== 'ECONNABORTED' && isServerSideError(error); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I don't think so. My mistake |
||
}; | ||
|
||
const DEFAULTS = { | ||
|
@@ -57,8 +67,8 @@ const exponentialBackoff = (config: RetryAlphaOptions) => { | |
export const setup = (client: Alpha) => { | ||
client.interceptors.response.use( | ||
undefined, | ||
async (err: any | AxiosError) => { | ||
if (!('config' in err && err.config.retry)) { | ||
async (err: any) => { | ||
if (!('config' in err && err.config?.retry)) { | ||
return Promise.reject(err); | ||
} | ||
|
||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
import axios from 'axios'; | ||
import axios, { AxiosHeaders, getAdapter } from 'axios'; | ||
import { chainAdapters } from '../../../src/adapters/helpers/chainAdapters'; | ||
import { AlphaAdapter } from '../../../src'; | ||
|
||
test('will set default adapter', () => { | ||
test('will set default adapter', async () => { | ||
const adapter: AlphaAdapter = jest.fn(); | ||
const defaultAdapter = axios.defaults.adapter = jest.fn(); | ||
const config = chainAdapters( | ||
{}, | ||
{ headers: new AxiosHeaders() }, | ||
() => false, | ||
adapter, | ||
); | ||
expect(defaultAdapter).not.toBeCalled(); | ||
expect(() => config.adapter!(config)).not.toThrow(); | ||
expect(defaultAdapter).toBeCalled(); | ||
expect(adapter).not.toBeCalled(); | ||
expect(defaultAdapter).not.toHaveBeenCalled(); | ||
|
||
expect(config.adapter).toHaveLength(1); // an array of adapters | ||
await expect(getAdapter(config.adapter)(config)).resolves.toBeUndefined(); | ||
expect(defaultAdapter).toHaveBeenCalled(); | ||
expect(adapter).not.toHaveBeenCalled(); | ||
}); |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Before the addition of
StatusCode
checks, was this function failing to detect some failures?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.
this function is refactored from
isRetryableError()
. it checked the statusCode of http request via Axios API (AxiosResponse
) only.These lines are for checking the status code of lambda function invocation via Lambda API (
InvocationResponse
). I could remove this one if aws internal error during lambda invocation is not retryable.