Adjust error page & the error handling of the trains load function. Intead of throwing error on no-results, an empty array is passed to the page. A 'no-results' component will roughly echo the error pages not-found.
This commit is contained in:
@@ -19,11 +19,13 @@ export const load: PageLoad = async ({ url }) => {
|
||||
});
|
||||
}
|
||||
|
||||
// Declared outside of the try so that it can be used in both the try and catch blocks
|
||||
let results: ApiTrainsTrainByHeadcode.TrainByHeadcodeResponse[]
|
||||
|
||||
try {
|
||||
const response = await OwlClient.trains.getByHeadcode(headcode, date, toc);
|
||||
|
||||
// Shouldn't be needed to cast the type...
|
||||
const results = (response.data);
|
||||
results = (response.data);
|
||||
return {
|
||||
title: headcode.toUpperCase(),
|
||||
results: results,
|
||||
@@ -36,11 +38,17 @@ export const load: PageLoad = async ({ url }) => {
|
||||
});
|
||||
} else if (e instanceof ApiError) {
|
||||
// Check if NO_RESULTS error, and return empty array if that is the case
|
||||
// Maybe adjust the resulting error depending on the ERROR Code?!
|
||||
throw error(20, {
|
||||
message: e.message,
|
||||
owlCode: 'API_ERROR',
|
||||
});
|
||||
if (e.code === "NOT_FOUND") {
|
||||
return {
|
||||
title: headcode.toUpperCase(),
|
||||
results: []
|
||||
}
|
||||
} else {
|
||||
throw error(e.status, {
|
||||
message: e.message,
|
||||
owlCode: 'API_ERROR',
|
||||
});
|
||||
}
|
||||
} else if (e instanceof Error) {
|
||||
throw error(500, {
|
||||
message: e.message,
|
||||
@@ -53,4 +61,4 @@ export const load: PageLoad = async ({ url }) => {
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user