Fix failure if NRCC messages are not present on StaffLDB
Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
@@ -67,6 +67,7 @@ async function arrDepBoardStaff(CRS) {
|
||||
const api = new ldb(ldbsvKey,true);
|
||||
console.time(`Fetch Staff LDB for ${CRS.toUpperCase()}`);
|
||||
const result = await api.call('GetArrivalDepartureBoardByCRS',options,false,false);
|
||||
console.log(`Upstream API Size: ${resultSize}`)
|
||||
console.timeEnd(`Fetch Staff LDB for ${CRS.toUpperCase()}`)
|
||||
try {
|
||||
const _staffLdb = staffStationTransform(result)
|
||||
|
||||
@@ -22,6 +22,7 @@ export function transform(input: any): StaffLdb | null {
|
||||
console.timeEnd("StaffLdb Transformation")
|
||||
return output
|
||||
} catch (err) {
|
||||
console.log("utils/translators/ldb/staffLdb.transform: Caught Error")
|
||||
console.log('Unable to parse data, assuming no data: ' + err)
|
||||
}
|
||||
console.timeEnd("StaffLdb Transformation")
|
||||
@@ -32,20 +33,23 @@ function transformDateTime(input: string): Date {
|
||||
return new Date(input)
|
||||
}
|
||||
|
||||
function transformNrcc(input: any): NrccMessage[] {
|
||||
function transformNrcc(input: any): NrccMessage[] | undefined {
|
||||
let output: NrccMessage[] = []
|
||||
let messages = input
|
||||
if (!Array.isArray(input?.message)) {
|
||||
messages = [input?.message]
|
||||
}
|
||||
for (const item of messages) {
|
||||
let message: NrccMessage = {
|
||||
severity: item?.severity,
|
||||
xhtmlMessage: removeNewlineAndPTag(item?.xhtmlMessage)
|
||||
if (messages.length) {
|
||||
for (const item of messages) {
|
||||
let message: NrccMessage = {
|
||||
severity: item?.severity,
|
||||
xhtmlMessage: removeNewlineAndPTag(item?.xhtmlMessage)
|
||||
}
|
||||
output.push(message)
|
||||
}
|
||||
output.push(message)
|
||||
}
|
||||
return output
|
||||
return output
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
function transformTrainServices(input: any): TrainServices[] {
|
||||
@@ -95,8 +99,7 @@ function transformLocation(input: any): ServiceLocation[] {
|
||||
}
|
||||
for (const item of locations) {
|
||||
const location: ServiceLocation = {
|
||||
tiploc: item?.tiploc,
|
||||
name: item?.locationName
|
||||
tiploc: item?.tiploc
|
||||
}
|
||||
if (item?.via) {
|
||||
location.via = item.via
|
||||
|
||||
Reference in New Issue
Block a user