From 87d5f004c0ba83efd3757593f88ebea93255236d Mon Sep 17 00:00:00 2001 From: Jannis R Date: Mon, 24 Jul 2017 14:25:43 +0200 Subject: [PATCH] flag HAFAS errors, 1.1.0 --- index.js | 10 ++++++++-- package.json | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index e6d1e08c..b84492ba 100644 --- a/index.js +++ b/index.js @@ -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 || {} diff --git a/package.json b/package.json index 4ff7e5ea..8979e4e2 100644 --- a/package.json +++ b/package.json @@ -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 ",