Skip to content
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

Merged
merged 4 commits into from
Mar 13, 2024
Merged

Conversation

camden11
Copy link
Contributor

Description and Context

Currently, you can use the --use-env flag on the CLI to pull certain config values from environment variables, but until now, setting the HTTP timeout this way wasn't supported. It's possible this could cause issues for customers using CLI commands in environments where using a hubspot.config.yml file doesn't work or doesn't make sense (see HubSpot/hubspot-cli#1015). This adds support for an HTTP_TIMEOUT environment variable.

It also makes some other more minor changes

  • Fixes bug in filemapper where timeout errors weren't being identified properly
  • Updates the axios config to show when errors were caused by timeouts. This will allow us to add error messaging to help users avoid timeout errors (planning on doing this in another PR)

Testing

Run a command with a request that takes a long time with a low timeout to confirm this is working.
Example:

HUBSPOT_PORTAL_ID=[your portal id] HUBSPOT_PERSONAL_ACCESS_KEY=[your personal access key] HTTP_TIMEOUT=3000 yarn hs fetch / ./ --use-env

TODO

  • Would like to update error messaging for all errors to suggest users change their timeout when timeout errors occur. I think it makes sense to wait until the CLI is 100% on local-dev-lib before we do this though, since local-dev-lib and cli-lib throw/handle errors differently

Who to Notify

@brandenrodgers @kemmerle

@@ -9,6 +9,10 @@ export const DEFAULT_USER_AGENT_HEADERS = {
'User-Agent': `HubSpot Local Dev Lib/${version}`,
};

const DEFAULT_TRANSITIONAL = {
clarifyTimeoutError: true,
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tells axios to use ETIMEDOUT as the code for timeout errors

@@ -736,6 +736,9 @@ function getConfigVariablesFromEnv() {
personalAccessKey: env[ENVIRONMENT_VARIABLES.HUBSPOT_PERSONAL_ACCESS_KEY],
portalId: parseInt(env[ENVIRONMENT_VARIABLES.HUBSPOT_PORTAL_ID] || '', 10),
refreshToken: env[ENVIRONMENT_VARIABLES.HUBSPOT_REFRESH_TOKEN],
httpTimeout: env[ENVIRONMENT_VARIABLES.HTTP_TIMEOUT]
? parseInt(env[ENVIRONMENT_VARIABLES.HTTP_TIMEOUT] || '')
Copy link
Contributor

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.

Copy link
Contributor Author

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 being NaN if not provided)

@@ -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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would isSpecifiedError help here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah maybe we should update this to be able to check for code

Copy link
Contributor

@brandenrodgers brandenrodgers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@camden11 camden11 merged commit 837d02f into main Mar 13, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants