db-vendo-client/lib/errors.js

303 lines
6 KiB
JavaScript
Raw Permalink Normal View History

2018-12-16 23:47:36 +01:00
const ACCESS_DENIED = 'ACCESS_DENIED'
const INVALID_REQUEST = 'INVALID_REQUEST'
const NOT_FOUND = 'NOT_FOUND'
const SERVER_ERROR = 'SERVER_ERROR'
2022-05-03 23:21:44 +02:00
class HafasError extends Error {
constructor (cleanMessage, hafasCode, props) {
const msg = hafasCode
? hafasCode + ': ' + cleanMessage
: cleanMessage
super(msg)
// generic props
this.isHafasError = true
// error-specific props
this.code = null
// By default, we take the blame, unless we know for sure.
this.isCausedByServer = false
this.hafasCode = hafasCode
Object.assign(this, props)
return this
}
}
class HafasAccessDeniedError extends HafasError {
constructor (cleanMessage, hafasCode, props) {
super(cleanMessage, hafasCode, props)
this.code = ACCESS_DENIED
return this
}
}
class HafasInvalidRequestError extends HafasError {
constructor (cleanMessage, hafasCode, props) {
super(cleanMessage, hafasCode, props)
this.code = INVALID_REQUEST
return this
}
}
class HafasNotFoundError extends HafasError {
constructor (cleanMessage, hafasCode, props) {
super(cleanMessage, hafasCode, props)
this.code = NOT_FOUND
return this
}
}
class HafasServerError extends HafasError {
constructor (cleanMessage, hafasCode, props) {
super(cleanMessage, hafasCode, props)
this.code = SERVER_ERROR
this.isCausedByServer = true
return this
}
}
2018-12-16 23:47:36 +01:00
const byErrorCode = Object.assign(Object.create(null), {
H_UNKNOWN: {
2022-05-03 23:21:44 +02:00
Error: HafasError,
message: 'unknown internal error',
2022-05-03 23:21:44 +02:00
props: {
shouldRetry: true,
},
},
2018-12-16 23:47:36 +01:00
AUTH: {
2022-05-03 23:21:44 +02:00
Error: HafasAccessDeniedError,
2018-12-16 23:49:32 +01:00
message: 'invalid or missing authentication data',
2022-05-03 23:21:44 +02:00
props: {
},
2018-12-16 23:47:36 +01:00
},
METHOD_NA: {
Error: HafasServerError,
message: 'method is not enabled',
props: {
},
},
2018-12-16 23:47:36 +01:00
R0001: {
2022-05-03 23:21:44 +02:00
Error: HafasInvalidRequestError,
2018-12-16 23:49:32 +01:00
message: 'unknown method',
2022-05-03 23:21:44 +02:00
props: {
},
2018-12-16 23:47:36 +01:00
},
R0002: {
2022-05-03 23:21:44 +02:00
Error: HafasInvalidRequestError,
2018-12-16 23:49:32 +01:00
message: 'invalid or missing request parameters',
2022-05-03 23:21:44 +02:00
props: {
},
2018-12-16 23:47:36 +01:00
},
R0007: {
2022-05-03 23:21:44 +02:00
Error: HafasServerError,
2018-12-16 23:49:32 +01:00
message: 'internal communication error',
2022-05-03 23:21:44 +02:00
props: {
shouldRetry: true,
},
2018-12-16 23:47:36 +01:00
},
R5000: {
2022-05-03 23:21:44 +02:00
Error: HafasAccessDeniedError,
2018-12-16 23:49:32 +01:00
message: 'access denied',
2022-05-03 23:21:44 +02:00
props: {
},
2018-12-16 23:47:36 +01:00
},
S1: {
2022-05-03 23:21:44 +02:00
Error: HafasServerError,
2018-12-16 23:49:32 +01:00
message: 'journeys search: a connection to the backend server couldn\'t be established',
2022-05-03 23:21:44 +02:00
props: {
shouldRetry: true,
},
2018-12-16 23:47:36 +01:00
},
2023-12-07 00:55:35 +01:00
PROBLEMS: {
Error: HafasServerError,
message: 'an unknown problem occured during search',
props: {
shouldRetry: true,
},
},
2018-12-16 23:47:36 +01:00
LOCATION: {
2022-05-03 23:21:44 +02:00
Error: HafasNotFoundError,
2018-12-16 23:49:32 +01:00
message: 'location/stop not found',
2022-05-03 23:21:44 +02:00
props: {
},
2018-12-16 23:47:36 +01:00
},
NO_MATCH: {
Error: HafasNotFoundError,
message: 'no results found',
props: {
},
},
PARAMETER: {
Error: HafasInvalidRequestError,
message: 'invalid parameter',
props: {
},
},
2018-12-16 23:47:36 +01:00
H390: {
2022-05-03 23:21:44 +02:00
Error: HafasInvalidRequestError,
2018-12-16 23:49:32 +01:00
message: 'journeys search: departure/arrival station replaced',
2022-05-03 23:21:44 +02:00
props: {
},
2018-12-16 23:47:36 +01:00
},
H410: {
// todo: or is it a client error?
2022-05-03 23:21:44 +02:00
Error: HafasServerError,
message: 'journeys search: incomplete response due to timetable change',
props: {
},
2018-12-16 23:47:36 +01:00
},
H455: {
2022-05-03 23:21:44 +02:00
Error: HafasInvalidRequestError,
2018-12-16 23:49:32 +01:00
message: 'journeys search: prolonged stop',
2022-05-03 23:21:44 +02:00
props: {
},
2018-12-16 23:47:36 +01:00
},
H460: {
2022-05-03 23:21:44 +02:00
Error: HafasInvalidRequestError,
2018-12-16 23:49:32 +01:00
message: 'journeys search: stop(s) passed multiple times',
2022-05-03 23:21:44 +02:00
props: {
},
2018-12-16 23:47:36 +01:00
},
H500: {
2022-05-03 23:21:44 +02:00
Error: HafasInvalidRequestError,
2018-12-16 23:49:32 +01:00
message: 'journeys search: too many trains, connection is not complete',
2022-05-03 23:21:44 +02:00
props: {
},
2018-12-16 23:47:36 +01:00
},
H890: {
2022-05-03 23:21:44 +02:00
Error: HafasNotFoundError,
2018-12-16 23:49:32 +01:00
message: 'journeys search unsuccessful',
2022-05-03 23:21:44 +02:00
props: {
shouldRetry: true,
},
2018-12-16 23:47:36 +01:00
},
H891: {
2022-05-03 23:21:44 +02:00
Error: HafasNotFoundError,
2018-12-16 23:49:32 +01:00
message: 'journeys search: no route found, try with an intermediate stations',
2022-05-03 23:21:44 +02:00
props: {
},
2018-12-16 23:47:36 +01:00
},
H892: {
2022-05-03 23:21:44 +02:00
Error: HafasInvalidRequestError,
2018-12-16 23:49:32 +01:00
message: 'journeys search: query too complex, try less intermediate stations',
2022-05-03 23:21:44 +02:00
props: {
},
2018-12-16 23:47:36 +01:00
},
H895: {
2022-05-03 23:21:44 +02:00
Error: HafasInvalidRequestError,
2018-12-16 23:49:32 +01:00
message: 'journeys search: departure & arrival are too near',
2022-05-03 23:21:44 +02:00
props: {
},
2018-12-16 23:47:36 +01:00
},
H899: {
// todo: or is it a client error?
2022-05-03 23:21:44 +02:00
Error: HafasServerError,
message: 'journeys search unsuccessful or incomplete due to timetable change',
props: {
},
2018-12-16 23:47:36 +01:00
},
H900: {
// todo: or is it a client error?
2022-05-03 23:21:44 +02:00
Error: HafasServerError,
message: 'journeys search unsuccessful or incomplete due to timetable change',
props: {
},
2018-12-16 23:47:36 +01:00
},
H9220: {
2022-05-03 23:21:44 +02:00
Error: HafasNotFoundError,
2018-12-16 23:49:32 +01:00
message: 'journeys search: no stations found close to the address',
2022-05-03 23:21:44 +02:00
props: {
},
2018-12-16 23:47:36 +01:00
},
H9230: {
2022-05-03 23:21:44 +02:00
Error: HafasServerError,
2018-12-16 23:49:32 +01:00
message: 'journeys search: an internal error occured',
2022-05-03 23:21:44 +02:00
props: {
shouldRetry: true,
},
2018-12-16 23:47:36 +01:00
},
H9240: {
2022-05-03 23:21:44 +02:00
Error: HafasNotFoundError,
2018-12-16 23:49:32 +01:00
message: 'journeys search unsuccessful',
2022-05-03 23:21:44 +02:00
props: {
shouldRetry: true,
},
2018-12-16 23:47:36 +01:00
},
H9250: {
2022-05-03 23:21:44 +02:00
Error: HafasServerError,
2018-12-16 23:49:32 +01:00
message: 'journeys search: leg query interrupted',
2022-05-03 23:21:44 +02:00
props: {
shouldRetry: true,
},
2018-12-16 23:47:36 +01:00
},
H9260: {
2022-05-03 23:21:44 +02:00
Error: HafasInvalidRequestError,
2018-12-16 23:49:32 +01:00
message: 'journeys search: unknown departure station',
2022-05-03 23:21:44 +02:00
props: {
},
2018-12-16 23:47:36 +01:00
},
H9280: {
2022-05-03 23:21:44 +02:00
Error: HafasInvalidRequestError,
2018-12-16 23:49:32 +01:00
message: 'journeys search: unknown intermediate station',
2022-05-03 23:21:44 +02:00
props: {
},
2018-12-16 23:47:36 +01:00
},
H9300: {
2022-05-03 23:21:44 +02:00
Error: HafasInvalidRequestError,
2018-12-16 23:49:32 +01:00
message: 'journeys search: unknown arrival station',
2022-05-03 23:21:44 +02:00
props: {
},
2018-12-16 23:47:36 +01:00
},
H9320: {
2022-05-03 23:21:44 +02:00
Error: HafasInvalidRequestError,
2018-12-16 23:49:32 +01:00
message: 'journeys search: the input is incorrect or incomplete',
2022-05-03 23:21:44 +02:00
props: {
},
2018-12-16 23:47:36 +01:00
},
H9360: {
2022-05-03 23:21:44 +02:00
Error: HafasInvalidRequestError,
2020-08-01 13:08:53 +02:00
message: 'journeys search: invalid date/time',
2022-05-03 23:21:44 +02:00
props: {
},
2018-12-16 23:47:36 +01:00
},
H9380: {
2022-05-03 23:21:44 +02:00
Error: HafasInvalidRequestError,
2018-12-16 23:49:32 +01:00
message: 'journeys search: departure/arrival/intermediate station defined more than once',
2022-05-03 23:21:44 +02:00
props: {
},
2018-12-16 23:47:36 +01:00
},
SQ001: {
2022-05-03 23:21:44 +02:00
Error: HafasServerError,
2018-12-16 23:49:32 +01:00
message: 'no departures/arrivals data available',
2022-05-03 23:21:44 +02:00
props: {
},
2018-12-16 23:47:36 +01:00
},
SQ005: {
2022-05-03 23:21:44 +02:00
Error: HafasNotFoundError,
2018-12-16 23:49:32 +01:00
message: 'no trips found',
2022-05-03 23:21:44 +02:00
props: {
},
2018-12-16 23:47:36 +01:00
},
TI001: {
2022-05-03 23:21:44 +02:00
Error: HafasServerError,
2018-12-16 23:49:32 +01:00
message: 'no trip info available',
2022-05-03 23:21:44 +02:00
props: {
shouldRetry: true,
},
2018-12-16 23:47:36 +01:00
}
})
2022-05-07 16:17:37 +02:00
export {
2018-12-16 23:47:36 +01:00
ACCESS_DENIED,
INVALID_REQUEST,
NOT_FOUND,
SERVER_ERROR,
2022-05-03 23:21:44 +02:00
HafasError,
HafasAccessDeniedError,
HafasInvalidRequestError,
HafasNotFoundError,
HafasServerError,
byErrorCode,
2018-12-16 23:47:36 +01:00
}