request: add response ID to error objects

This commit is contained in:
Jannis R 2020-02-04 18:42:11 +01:00
parent 4837c2309e
commit dfff999406
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5

View file

@ -19,7 +19,7 @@ const randomizeUserAgent = (userAgent) => {
const md5 = input => createHash('md5').update(input).digest()
const addErrorInfo = (err, errorCode, errorText) => {
const addErrorInfo = (err, errorCode, errorText, responseId) => {
if (byErrorCode[errorCode]) {
Object.assign(err, byErrorCode[errorCode])
if (errorCode) err.hafasErrorCode = errorCode
@ -27,6 +27,7 @@ const addErrorInfo = (err, errorCode, errorText) => {
} else {
err.code = errorCode || null
err.message = errorText || errorCode || null
err.responseId = responseId || null
}
}
@ -96,7 +97,7 @@ const request = (ctx, userAgent, reqData) => {
if (DEBUG) console.error(JSON.stringify(b))
if (b.err && b.err !== 'OK') {
addErrorInfo(err, b.err, b.errTxt)
addErrorInfo(err, b.err, b.errTxt, b.id)
throw err
}
if (!b.svcResL || !b.svcResL[0]) {
@ -104,7 +105,7 @@ const request = (ctx, userAgent, reqData) => {
throw err
}
if (b.svcResL[0].err !== 'OK') {
addErrorInfo(err, b.svcResL[0].err, b.svcResL[0].errTxt)
addErrorInfo(err, b.svcResL[0].err, b.svcResL[0].errTxt, b.id)
throw err
}