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:
2026-04-28 18:13:05 +01:00
parent 16d929fad1
commit 68af07b9bd
4 changed files with 24 additions and 15 deletions

View File

@@ -7,10 +7,11 @@
</script>
<div class="error-wrapper">
{#if page.status == 20}
<!-- Check the values passed in the ApiError object and decide what to present -->
{#if page.status == 404}
<!-- Warning no data image -->
<img class="err-img" src={noResult} alt="" role="presentation" width="200" height="200" />
{:else}
<!-- STOP Error image -->
<img class="err-img" src={stopErr} alt="" role="presentation" width="150" height="210" />
{/if}
<h2 class="label">{page.status}</h2>

View File

@@ -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 }) => {
})
}
}
}
}