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

Add a timeout to fetch() + configurable environment variable #24

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion bin/ncm-ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ const graphql = require('../lib/graphql')
const chalk = require('chalk')
const fetch = require('node-fetch')

// Setting up a timeout to be used with fetch() – will use the NCM_TIMEOUT environment
// variable or default to 2 minutes (120 seconds / 120000 milliseconds)
const timeout = process.env.NCM_TIMEOUT
? Number(process.env.NCM_TIMEOUT) * 1000
Copy link

Choose a reason for hiding this comment

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

still need to check for a non-numeric string in the env var:

$ node -p 'Number("foo") * 1000'
NaN

timeout will end up being a NaN in that case

: 120000

if (!process.env.NCM_TOKEN) {
console.error(`
Usage
Expand Down Expand Up @@ -49,7 +55,8 @@ const getUserDetails = async () => {
const res = await fetch(`${api.accounts}/user/details`, {
headers: {
Authorization: `Bearer ${token}`
}
},
timeout
})
const details = await res.json()
if (
Expand Down