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

8
package-lock.json generated
View File

@@ -8,7 +8,7 @@
"name": "web-pwa",
"version": "0.0.1",
"dependencies": {
"@owlboard/owlboard-ts": "^3.0.0-dev.20260427T2348",
"@owlboard/owlboard-ts": "^3.0.0-dev.20260428T2753",
"@tabler/icons-svelte": "^3.40.0"
},
"devDependencies": {
@@ -786,9 +786,9 @@
"license": "MIT"
},
"node_modules/@owlboard/owlboard-ts": {
"version": "3.0.0-dev.20260427T2348",
"resolved": "https://git.fjla.uk/api/packages/OwlBoard/npm/%40owlboard%2Fowlboard-ts/-/3.0.0-dev.20260427T2348/owlboard-ts-3.0.0-dev.20260427t2348.tgz",
"integrity": "sha512-ZZ6h8zSnL/FyEZ6ZSekhK781/5TYMj6y6atRVwKiPH6TfXxauMdEimYCOKQIcoskseH7wItEZRFGAOUDAY3q7w==",
"version": "3.0.0-dev.20260428T2753",
"resolved": "https://git.fjla.uk/api/packages/OwlBoard/npm/%40owlboard%2Fowlboard-ts/-/3.0.0-dev.20260428T2753/owlboard-ts-3.0.0-dev.20260428t2753.tgz",
"integrity": "sha512-8kZ6oP8MFz+1FHyYZS7lAYSk0Kamq80KAsIcef32/lZTT0GhIjyjZcabWZ0uipAYYsKvGqdm1wtxDrtgKPN/DQ==",
"license": "GPL-3.0",
"dependencies": {
"@owlboard/api-schema-types": "^3.0.3-alpha1",

View File

@@ -41,7 +41,7 @@
"vitest-browser-svelte": "^2.0.2"
},
"dependencies": {
"@owlboard/owlboard-ts": "^3.0.0-dev.20260427T2348",
"@owlboard/owlboard-ts": "^3.0.0-dev.20260428T2753",
"@tabler/icons-svelte": "^3.40.0"
}
}

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, {
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,