Skip to content

Commit

Permalink
fix: ensure reflected timeout is half timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Jan 12, 2021
1 parent 1236f5e commit f6ae775
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,12 @@ const REQ_TIMEOUT = 8000

const fetch = (
url,
{
reflect = false,
toEncode,
timeout = reflect ? REQ_TIMEOUT / 2 : REQ_TIMEOUT,
...opts
}
{ reflect = false, toEncode, timeout = REQ_TIMEOUT, ...opts }
) =>
new PCancelable(async (resolve, reject, onCancel) => {
const req = got(url, {
responseType: 'buffer',
timeout,
timeout: reflect ? timeout / 2 : timeout,
...opts
})

Expand All @@ -53,12 +48,12 @@ const fetch = (
return reflect
? resolve({ isRejected: true, error })
: resolve({
url,
html: '',
mode: 'fetch',
headers: error.response ? error.response.headers : {},
statusCode: error.response ? error.response.statusCode : undefined
})
url,
html: '',
mode: 'fetch',
headers: error.response ? error.response.headers : {},
statusCode: error.response ? error.response.statusCode : undefined
})
}
})

Expand Down

0 comments on commit f6ae775

Please sign in to comment.