mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
handle METHOD_NA/NO_MATCH/PARAMETER errors ✅
This commit is contained in:
parent
9b263bb379
commit
1000e48dfd
4 changed files with 129 additions and 5 deletions
|
@ -59,11 +59,6 @@ class HafasServerError extends HafasError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://gist.github.com/derhuerst/79d49c0f04c1c192a5d15756e5af575f/edit
|
|
||||||
// todo:
|
|
||||||
// `code: 'METHOD_NA', message: 'HCI Service: service method disabled'`
|
|
||||||
// "err": "PARAMETER", "errTxt": "HCI Service: parameter invalid"
|
|
||||||
// "err": "PARAMETER", "errTxt": "HCI Service: parameter invalid","errTxtOut":"Während der Suche ist ein interner Fehler aufgetreten"
|
|
||||||
const byErrorCode = Object.assign(Object.create(null), {
|
const byErrorCode = Object.assign(Object.create(null), {
|
||||||
H_UNKNOWN: {
|
H_UNKNOWN: {
|
||||||
Error: HafasError,
|
Error: HafasError,
|
||||||
|
@ -78,6 +73,12 @@ const byErrorCode = Object.assign(Object.create(null), {
|
||||||
props: {
|
props: {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
METHOD_NA: {
|
||||||
|
Error: HafasServerError,
|
||||||
|
message: 'method is not enabled',
|
||||||
|
props: {
|
||||||
|
},
|
||||||
|
},
|
||||||
R0001: {
|
R0001: {
|
||||||
Error: HafasInvalidRequestError,
|
Error: HafasInvalidRequestError,
|
||||||
message: 'unknown method',
|
message: 'unknown method',
|
||||||
|
@ -116,6 +117,18 @@ const byErrorCode = Object.assign(Object.create(null), {
|
||||||
props: {
|
props: {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
NO_MATCH: {
|
||||||
|
Error: HafasNotFoundError,
|
||||||
|
message: 'no results found',
|
||||||
|
props: {
|
||||||
|
},
|
||||||
|
},
|
||||||
|
PARAMETER: {
|
||||||
|
Error: HafasInvalidRequestError,
|
||||||
|
message: 'invalid parameter',
|
||||||
|
props: {
|
||||||
|
},
|
||||||
|
},
|
||||||
H390: {
|
H390: {
|
||||||
Error: HafasInvalidRequestError,
|
Error: HafasInvalidRequestError,
|
||||||
message: 'journeys search: departure/arrival station replaced',
|
message: 'journeys search: departure/arrival station replaced',
|
||||||
|
|
27
test/fixtures/error-no-match.json
vendored
Normal file
27
test/fixtures/error-no-match.json
vendored
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
{
|
||||||
|
"ver": "1.42",
|
||||||
|
"lang": "deu",
|
||||||
|
"id": "pz2cgmquimu5pm4k",
|
||||||
|
"err": "OK",
|
||||||
|
"graph": {
|
||||||
|
"id": "standard",
|
||||||
|
"index": 0
|
||||||
|
},
|
||||||
|
"subGraph": {
|
||||||
|
"id": "global",
|
||||||
|
"index": 0
|
||||||
|
},
|
||||||
|
"view": {
|
||||||
|
"id": "standard",
|
||||||
|
"index": 0,
|
||||||
|
"type": "WGS84"
|
||||||
|
},
|
||||||
|
"svcResL": [
|
||||||
|
{
|
||||||
|
"meth": "JourneyMatch",
|
||||||
|
"err": "NO_MATCH",
|
||||||
|
"errTxt": "Nothing found.",
|
||||||
|
"errTxtOut": "Während der Suche ist leider ein interner Fehler aufgetreten. Bitte wenden Sie sich an unsere Serviceauskunft unter Tel. 0421 596059."
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
28
test/fixtures/error-parameter.json
vendored
Normal file
28
test/fixtures/error-parameter.json
vendored
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
{
|
||||||
|
"ver": "1.44",
|
||||||
|
"ext": "BVG.1",
|
||||||
|
"lang": "deu",
|
||||||
|
"id": "xmwk2kueimst964k",
|
||||||
|
"err": "OK",
|
||||||
|
"graph": {
|
||||||
|
"id": "standard",
|
||||||
|
"index": 0
|
||||||
|
},
|
||||||
|
"subGraph": {
|
||||||
|
"id": "global",
|
||||||
|
"index": 0
|
||||||
|
},
|
||||||
|
"view": {
|
||||||
|
"id": "standard",
|
||||||
|
"index": 0,
|
||||||
|
"type": "WGS84"
|
||||||
|
},
|
||||||
|
"svcResL": [
|
||||||
|
{
|
||||||
|
"meth": "JourneyDetails",
|
||||||
|
"err": "PARAMETER",
|
||||||
|
"errTxt": "HCI Service: parameter invalid",
|
||||||
|
"errTxtOut": "Während der Suche ist ein interner Fehler aufgetreten"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -73,6 +73,62 @@ tap.test('checkIfResponseIsOk properly throws HAFAS "LOCATION" errors', (t) => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
tap.test('checkIfResponseIsOk properly throws HAFAS "NO_MATCH" errors', (t) => {
|
||||||
|
try {
|
||||||
|
checkIfResIsOk({
|
||||||
|
body: resNoMatch,
|
||||||
|
errProps: {secret},
|
||||||
|
})
|
||||||
|
} catch (err) {
|
||||||
|
t.ok(err)
|
||||||
|
|
||||||
|
t.ok(err instanceof HafasError)
|
||||||
|
t.equal(err.isHafasError, true)
|
||||||
|
t.equal(err.message.slice(0, 10), 'NO_MATCH: ')
|
||||||
|
t.ok(err.message.length > 10)
|
||||||
|
|
||||||
|
t.ok(err instanceof HafasNotFoundError)
|
||||||
|
t.equal(err.isCausedByServer, false)
|
||||||
|
t.equal(err.code, NOT_FOUND)
|
||||||
|
t.equal(err.hafasCode, 'NO_MATCH')
|
||||||
|
|
||||||
|
t.equal(err.hafasResponseId, resNoMatch.id)
|
||||||
|
t.equal(err.hafasMessage, 'Nothing found.')
|
||||||
|
t.equal(err.hafasDescription, 'Während der Suche ist leider ein interner Fehler aufgetreten. Bitte wenden Sie sich an unsere Serviceauskunft unter Tel. 0421 596059.')
|
||||||
|
t.equal(err.secret, secret)
|
||||||
|
|
||||||
|
t.end()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
tap.test('checkIfResponseIsOk properly throws HAFAS "PARAMETER" errors', (t) => {
|
||||||
|
try {
|
||||||
|
checkIfResIsOk({
|
||||||
|
body: resParameter,
|
||||||
|
errProps: {secret},
|
||||||
|
})
|
||||||
|
} catch (err) {
|
||||||
|
t.ok(err)
|
||||||
|
|
||||||
|
t.ok(err instanceof HafasError)
|
||||||
|
t.equal(err.isHafasError, true)
|
||||||
|
t.equal(err.message.slice(0, 11), 'PARAMETER: ')
|
||||||
|
t.ok(err.message.length > 11)
|
||||||
|
|
||||||
|
t.ok(err instanceof HafasInvalidRequestError)
|
||||||
|
t.equal(err.isCausedByServer, false)
|
||||||
|
t.equal(err.code, INVALID_REQUEST)
|
||||||
|
t.equal(err.hafasCode, 'PARAMETER')
|
||||||
|
|
||||||
|
t.equal(err.hafasResponseId, resParameter.id)
|
||||||
|
t.equal(err.hafasMessage, 'HCI Service: parameter invalid')
|
||||||
|
t.equal(err.hafasDescription, 'Während der Suche ist ein interner Fehler aufgetreten')
|
||||||
|
t.equal(err.secret, secret)
|
||||||
|
|
||||||
|
t.end()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
tap.test('checkIfResponseIsOk properly parses an unknown HAFAS errors', (t) => {
|
tap.test('checkIfResponseIsOk properly parses an unknown HAFAS errors', (t) => {
|
||||||
const body = {
|
const body = {
|
||||||
ver: '1.42',
|
ver: '1.42',
|
||||||
|
|
Loading…
Add table
Reference in a new issue