mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
fix hafas errors 🐛, 1.2.6
This commit is contained in:
parent
d72fdc8092
commit
237c1428c4
2 changed files with 11 additions and 5 deletions
14
index.js
14
index.js
|
@ -20,6 +20,11 @@ const defaults = {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const hafasError = (err) => {
|
||||||
|
err.isHafasError = true
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
const createRequest = (opt) => {
|
const createRequest = (opt) => {
|
||||||
opt = Object.assign({}, defaults, opt)
|
opt = Object.assign({}, defaults, opt)
|
||||||
|
|
||||||
|
@ -42,15 +47,16 @@ const createRequest = (opt) => {
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
const err = new Error(res.statusText)
|
const err = new Error(res.statusText)
|
||||||
err.statusCode = res.status
|
err.statusCode = res.status
|
||||||
err.isHafasError = true
|
throw hafasError(err)
|
||||||
throw err
|
|
||||||
}
|
}
|
||||||
return res.json()
|
return res.json()
|
||||||
})
|
})
|
||||||
.then((b) => {
|
.then((b) => {
|
||||||
if (b.err) throw hafasError(b.err)
|
if (b.err) throw hafasError(new Error(b.err))
|
||||||
if (!b.svcResL || !b.svcResL[0]) throw new Error('invalid response')
|
if (!b.svcResL || !b.svcResL[0]) throw new Error('invalid response')
|
||||||
if (b.svcResL[0].err !== 'OK') throw hafasError(b.svcResL[0].errTxt)
|
if (b.svcResL[0].err !== 'OK') {
|
||||||
|
throw hafasError(new Error(b.svcResL[0].errTxt))
|
||||||
|
}
|
||||||
const d = b.svcResL[0].res
|
const d = b.svcResL[0].res
|
||||||
const c = d.common || {}
|
const c = d.common || {}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "hafas-client",
|
"name": "hafas-client",
|
||||||
"description": "JavaScript client for HAFAS mobile APIs.",
|
"description": "JavaScript client for HAFAS mobile APIs.",
|
||||||
"version": "1.2.5",
|
"version": "1.2.6",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"files": [
|
"files": [
|
||||||
"index.js",
|
"index.js",
|
||||||
|
|
Loading…
Add table
Reference in a new issue