mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
reachableFrom: retry 🐛
This commit is contained in:
parent
dfad3d9d84
commit
035877c368
2 changed files with 48 additions and 33 deletions
16
index.js
16
index.js
|
@ -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
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Add table
Reference in a new issue