Skip to content

Commit

Permalink
Add response timeout settings
Browse files Browse the repository at this point in the history
  • Loading branch information
corys committed Jan 25, 2022
1 parent cc8f30e commit f3e3992
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ const fetchCycle = async (cycle = 'Current') => {
const response = await superagent
.get(BASE_URL)
.set('Accept', ACCEPT)
.timeout({ deadline: 30000 })
.timeout({
response: 30e3,
deadline: 60e3
})
.retry(3)

const $ = cheerio.load(response.text)
Expand All @@ -62,12 +65,12 @@ const fetchCycle = async (cycle = 'Current') => {
terminalProcedures.fetchCycle = fetchCycle

terminalProcedures.getCycleEffectiveDates = async (cycle = 'Current') => {
const { text: currentCycle, } = await fetchCycle(cycle)
if (!currentCycle) {
console.warn(`Could not retrieve ${cycle} cycle effective dates`)
const currentCycle = await fetchCycle(cycle)
if (!currentCycle || !currentCycle.text) {
console.warn(`${cycle} cycle effective dates not found or not available.`)
return
}
return parseEffectiveDates(currentCycle.replace(/(\n|\t)/gm, ''))
return parseEffectiveDates(currentCycle.text.replace(/(\n|\t)/gm, ''))
}

terminalProcedures.currentCycleEffectiveDates = async () => {
Expand All @@ -79,8 +82,8 @@ terminalProcedures.currentCycleEffectiveDates = async () => {
*/
const fetchCurrentCycleCode = async () => {
const cycle = await fetchCycle('Current')
if (!cycle) {
console.warn('Current cycle not found or not available.')
if (!cycle || !cycle.val ) {
console.warn('Current cycle code not found or not available.')
return null
}
return cycle.val
Expand All @@ -93,8 +96,8 @@ terminalProcedures.fetchCurrentCycleCode = fetchCurrentCycleCode
*/
const fetchNextCycleCode = async () => {
const cycle = await fetchCycle('Next')
if (!cycle) {
console.warn('Next cycle not found or not available. The Next cycle is available 19 days before the end of the current cycle.')
if (!cycle || !cycle.val) {
console.warn('Next cycle code not found or not available. The Next cycle is available 19 days before the end of the current cycle.')
return null
}
return cycle.val
Expand Down Expand Up @@ -197,7 +200,10 @@ const listOne = async (icao, options) => {
const getProcedures = async url => superagent
.get(url)
.set('Accept', ACCEPT)
.timeout({ deadline: 30000 })
.timeout({
response: 10e3,
deadline: 60e3
})
.retry(3)
.then(res => parse(res.text))

Expand Down

0 comments on commit f3e3992

Please sign in to comment.