-
Notifications
You must be signed in to change notification settings - Fork 3
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
Support HTTP_TIMEOUT environment variable #116
Changes from 3 commits
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 |
---|---|---|
|
@@ -9,6 +9,10 @@ export const DEFAULT_USER_AGENT_HEADERS = { | |
'User-Agent': `HubSpot Local Dev Lib/${version}`, | ||
}; | ||
|
||
const DEFAULT_TRANSITIONAL = { | ||
clarifyTimeoutError: true, | ||
}; | ||
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 tells axios to use |
||
|
||
export function getAxiosConfig( | ||
options: AxiosConfigOptions | ||
): AxiosRequestConfig { | ||
|
@@ -26,6 +30,7 @@ export function getAxiosConfig( | |
...(headers || {}), | ||
}, | ||
timeout: httpTimeout || 15000, | ||
transitional: DEFAULT_TRANSITIONAL, | ||
...rest, | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -265,7 +265,7 @@ async function writeFileMapperNode( | |
} | ||
|
||
function isTimeout(err: BaseError): boolean { | ||
return !!err && (err.status === 408 || err.code === 'ESOCKETTIMEDOUT'); | ||
return !!err && (err.status === 408 || err.code === 'ETIMEDOUT'); | ||
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. Would isSpecifiedError help here? 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. Ah maybe we should update this to be able to check for |
||
} | ||
|
||
async function downloadFile( | ||
|
@@ -332,22 +332,13 @@ export async function fetchFolderFromApi( | |
src, | ||
}); | ||
} | ||
try { | ||
const srcPath = isRoot ? '@root' : src; | ||
const queryValues = getFileMapperQueryValues(mode, options); | ||
const node = isHubspot | ||
? await downloadDefault(accountId, srcPath, queryValues) | ||
: await download(accountId, srcPath, queryValues); | ||
logger.log(i18n(`${i18nKey}.folderFetch`, { src, accountId })); | ||
return node; | ||
} catch (err) { | ||
const error = err as BaseError; | ||
if (isHubspot && isTimeout(error)) { | ||
throwErrorWithMessage(`${i18nKey}.errors.assetTimeout`, {}, error); | ||
} else { | ||
throwError(error); | ||
} | ||
} | ||
const srcPath = isRoot ? '@root' : src; | ||
const queryValues = getFileMapperQueryValues(mode, options); | ||
const node = isHubspot | ||
? await downloadDefault(accountId, srcPath, queryValues) | ||
: await download(accountId, srcPath, queryValues); | ||
logger.log(i18n(`${i18nKey}.folderFetch`, { src, accountId })); | ||
return node; | ||
} | ||
|
||
async function downloadFolder( | ||
|
@@ -401,11 +392,16 @@ async function downloadFolder( | |
throwErrorWithMessage(`${i18nKey}.errors.incompleteFetch`, { src }); | ||
} | ||
} catch (err) { | ||
throwErrorWithMessage( | ||
`${i18nKey}.errors.failedToFetchFolder`, | ||
{ src, dest: destPath }, | ||
err as AxiosError | ||
); | ||
const error = err as AxiosError; | ||
if (isTimeout(error)) { | ||
throwErrorWithMessage(`${i18nKey}.errors.assetTimeout`, {}, error); | ||
} else { | ||
throwErrorWithMessage( | ||
`${i18nKey}.errors.failedToFetchFolder`, | ||
{ src, dest: destPath }, | ||
err as AxiosError | ||
); | ||
} | ||
} | ||
} | ||
|
||
|
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.
Is this part necessary?
env[ENVIRONMENT_VARIABLES.HTTP_TIMEOUT] || ''
Since
env[ENVIRONMENT_VARIABLES.HTTP_TIMEOUT]
would already have to resolve to true for this section of the ternary to run.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.
Oh good catch, that was left over from before I added the ternary (and would end with
httpTimeout
beingNaN
if not provided)