reachableFrom: retry 🐛

This commit is contained in:
Jannis R 2018-09-03 20:38:56 +02:00
parent dfad3d9d84
commit 035877c368
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
2 changed files with 48 additions and 33 deletions

View file

@ -4,6 +4,7 @@ const minBy = require('lodash/minBy')
const maxBy = require('lodash/maxBy')
const isObj = require('lodash/isObject')
const sortBy = require('lodash/sortBy')
const pRetry = require('p-retry')
const defaultProfile = require('./lib/default-profile')
const createParseBitmask = require('./parse/products-bitmask')
@ -474,6 +475,7 @@ const createClient = (profile, userAgent, request = _request) => {
}, opt)
if (Number.isNaN(+opt.when)) throw new Error('opt.when is invalid')
const refetch = () => {
return request(profile, userAgent, opt, {
meth: 'LocGeoReach',
req: {
@ -489,7 +491,12 @@ const createClient = (profile, userAgent, request = _request) => {
}
})
.then((d) => {
if (!Array.isArray(d.posL)) throw new Error('invalid response')
if (!Array.isArray(d.posL)) {
console.error('d', d)
const err = new Error('invalid response')
err.shouldRetry = true
throw err
}
const byDuration = []
let i = 0, lastDuration = NaN
@ -511,6 +518,13 @@ const createClient = (profile, userAgent, request = _request) => {
})
}
return pRetry(refetch, {
retries: 3,
factor: 2,
minTimeout: 2 * 1000
})
}
const client = {departures, arrivals, journeys, locations, station, nearby}
if (profile.trip) client.trip = trip
if (profile.radar) client.radar = radar

View file

@ -40,6 +40,7 @@
"gps-distance": "0.0.4",
"lodash": "^4.17.5",
"luxon": "^1.3.0",
"p-retry": "^2.0.0",
"p-throttle": "^1.1.0",
"pinkie-promise": "^2.0.1",
"query-string": "^6.0.0",