flag HAFAS errors, 1.1.0

This commit is contained in:
Jannis R 2017-07-24 14:25:43 +02:00
parent 412e1c551f
commit 87d5f004c0
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
2 changed files with 9 additions and 3 deletions

View file

@ -17,6 +17,12 @@ const defaults = {
const hafasError = (msg) => {
const err = new Error(msg)
err.isHafasError = true
return err
}
const request = (opt) => {
opt = Object.assign({}, defaults, opt)
@ -35,9 +41,9 @@ const request = (opt) => {
.then((res) => {
const b = res.body
if (b.err) throw new Error(b.err)
if (b.err) throw hafasError(b.err)
if (!b.svcResL || !b.svcResL[0]) throw new Error('invalid response')
if (b.svcResL[0].err !== 'OK') throw new Error(b.svcResL[0].errTxt)
if (b.svcResL[0].err !== 'OK') throw hafasError(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.0.2",
"version": "1.1.0",
"main": "index.js",
"files": ["index.js", "parse.js", "stringify.js"],
"author": "Jannis R <mail@jannisr.de>",