From 237c1428c4b2a0ed630339d71a29aa37419fe431 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Mon, 6 Nov 2017 21:16:14 +0100 Subject: [PATCH] fix hafas errors :bug:, 1.2.6 --- index.js | 14 ++++++++++---- package.json | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index a353f7de..51b58929 100644 --- a/index.js +++ b/index.js @@ -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 || {} diff --git a/package.json b/package.json index 4f9cb205..8ad11ad1 100644 --- a/package.json +++ b/package.json @@ -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",