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", "name": "web-pwa",
"version": "0.0.1", "version": "0.0.1",
"dependencies": { "dependencies": {
"@owlboard/owlboard-ts": "^3.0.0-dev.20260427T2348", "@owlboard/owlboard-ts": "^3.0.0-dev.20260428T2753",
"@tabler/icons-svelte": "^3.40.0" "@tabler/icons-svelte": "^3.40.0"
}, },
"devDependencies": { "devDependencies": {
@@ -786,9 +786,9 @@
"license": "MIT" "license": "MIT"
}, },
"node_modules/@owlboard/owlboard-ts": { "node_modules/@owlboard/owlboard-ts": {
"version": "3.0.0-dev.20260427T2348", "version": "3.0.0-dev.20260428T2753",
"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", "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-ZZ6h8zSnL/FyEZ6ZSekhK781/5TYMj6y6atRVwKiPH6TfXxauMdEimYCOKQIcoskseH7wItEZRFGAOUDAY3q7w==", "integrity": "sha512-8kZ6oP8MFz+1FHyYZS7lAYSk0Kamq80KAsIcef32/lZTT0GhIjyjZcabWZ0uipAYYsKvGqdm1wtxDrtgKPN/DQ==",
"license": "GPL-3.0", "license": "GPL-3.0",
"dependencies": { "dependencies": {
"@owlboard/api-schema-types": "^3.0.3-alpha1", "@owlboard/api-schema-types": "^3.0.3-alpha1",

View File

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

View File

@@ -7,10 +7,11 @@
</script> </script>
<div class="error-wrapper"> <div class="error-wrapper">
{#if page.status == 20} {#if page.status == 404}
<!-- Check the values passed in the ApiError object and decide what to present --> <!-- Warning no data image -->
<img class="err-img" src={noResult} alt="" role="presentation" width="200" height="200" /> <img class="err-img" src={noResult} alt="" role="presentation" width="200" height="200" />
{:else} {:else}
<!-- STOP Error image -->
<img class="err-img" src={stopErr} alt="" role="presentation" width="150" height="210" /> <img class="err-img" src={stopErr} alt="" role="presentation" width="150" height="210" />
{/if} {/if}
<h2 class="label">{page.status}</h2> <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 { try {
const response = await OwlClient.trains.getByHeadcode(headcode, date, toc); const response = await OwlClient.trains.getByHeadcode(headcode, date, toc);
// Shouldn't be needed to cast the type... results = (response.data);
const results = (response.data);
return { return {
title: headcode.toUpperCase(), title: headcode.toUpperCase(),
results: results, results: results,
@@ -36,11 +38,17 @@ export const load: PageLoad = async ({ url }) => {
}); });
} else if (e instanceof ApiError) { } else if (e instanceof ApiError) {
// Check if NO_RESULTS error, and return empty array if that is the case // Check if NO_RESULTS error, and return empty array if that is the case
// Maybe adjust the resulting error depending on the ERROR Code?! if (e.code === "NOT_FOUND") {
throw error(20, { return {
message: e.message, title: headcode.toUpperCase(),
owlCode: 'API_ERROR', results: []
}); }
} else {
throw error(e.status, {
message: e.message,
owlCode: 'API_ERROR',
});
}
} else if (e instanceof Error) { } else if (e instanceof Error) {
throw error(500, { throw error(500, {
message: e.message, message: e.message,