From e032ec1acd5f4bd469b7444f35e9bce260c780b4 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Wed, 1 Apr 2020 19:03:36 +0200 Subject: [PATCH] "invalid response" error: add isHafasError flag So that consuming code can tell that this error is caused by an invalid/unexpected response from HAFAS. --- index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 0a0abf89..96f36e7d 100644 --- a/index.js +++ b/index.js @@ -256,7 +256,11 @@ const createClient = (profile, userAgent, opt = {}) => { return profile.request({profile, opt}, userAgent, req) .then(({res, common}) => { if (!Array.isArray(res.outConL) || !res.outConL[0]) { - throw new Error('invalid response') + const err = new Error('invalid response') + // technically this is not a HAFAS error + // todo: find a different flag with decent DX + err.isHafasError = true + throw err } const ctx = {profile, opt, common, res} @@ -303,7 +307,11 @@ const createClient = (profile, userAgent, opt = {}) => { .then(({res, common}) => { if (!res || !Array.isArray(res.locL) || !res.locL[0]) { // todo: proper stack trace? - throw new Error('invalid response') + const err = new Error('invalid response') + // technically this is not a HAFAS error + // todo: find a different flag with decent DX + err.isHafasError = true + throw err } const ctx = {profile, opt, res, common}