fix hafas errors 🐛, 1.2.6

This commit is contained in:
Jannis R 2017-11-06 21:16:14 +01:00
parent d72fdc8092
commit 237c1428c4
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
2 changed files with 11 additions and 5 deletions

View file

@ -20,6 +20,11 @@ const defaults = {
const hafasError = (err) => {
err.isHafasError = true
return err
}
const createRequest = (opt) => {
opt = Object.assign({}, defaults, opt)
@ -42,15 +47,16 @@ const createRequest = (opt) => {
if (!res.ok) {
const err = new Error(res.statusText)
err.statusCode = res.status
err.isHafasError = true
throw err
throw hafasError(err)
}
return res.json()
})
.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[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 c = d.common || {}

View file

@ -1,7 +1,7 @@
{
"name": "hafas-client",
"description": "JavaScript client for HAFAS mobile APIs.",
"version": "1.2.5",
"version": "1.2.6",
"main": "index.js",
"files": [
"index.js",