mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
flag HAFAS errors, 1.1.0
This commit is contained in:
parent
412e1c551f
commit
87d5f004c0
2 changed files with 9 additions and 3 deletions
10
index.js
10
index.js
|
@ -17,6 +17,12 @@ const defaults = {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const hafasError = (msg) => {
|
||||||
|
const err = new Error(msg)
|
||||||
|
err.isHafasError = true
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
const request = (opt) => {
|
const request = (opt) => {
|
||||||
opt = Object.assign({}, defaults, opt)
|
opt = Object.assign({}, defaults, opt)
|
||||||
|
|
||||||
|
@ -35,9 +41,9 @@ const request = (opt) => {
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
const b = res.body
|
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 || !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 d = b.svcResL[0].res
|
||||||
const c = d.common || {}
|
const c = d.common || {}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "hafas-client",
|
"name": "hafas-client",
|
||||||
"description": "JavaScript client for HAFAS mobile APIs.",
|
"description": "JavaScript client for HAFAS mobile APIs.",
|
||||||
"version": "1.0.2",
|
"version": "1.1.0",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"files": ["index.js", "parse.js", "stringify.js"],
|
"files": ["index.js", "parse.js", "stringify.js"],
|
||||||
"author": "Jannis R <mail@jannisr.de>",
|
"author": "Jannis R <mail@jannisr.de>",
|
||||||
|
|
Loading…
Add table
Reference in a new issue