-
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
Changes from all commits
770218d
728ba11
1b58338
20c701b
c042dae
642b298
06b3b0d
f9a58ed
0690f50
0bf1586
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
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. Before the addition of 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. this function is refactored from These lines are for checking the status code of lambda function invocation via Lambda API ( |
||
|| _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,7 +67,7 @@ const exponentialBackoff = (config: RetryAlphaOptions) => { | |
export const setup = (client: Alpha) => { | ||
client.interceptors.response.use( | ||
undefined, | ||
async (err: any | AxiosError) => { | ||
async (err: any) => { | ||
if (!('config' in err && err.config.retry)) { | ||
return Promise.reject(err); | ||
} | ||
|
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(); | ||
}); |
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.
I locked it to
3.0.0
to be able to runyarn lint
on node.js v14.