Compare commits

...

2 Commits

Author SHA1 Message Date
Fred Boniface 0ce32f4a34 Add comments 2023-09-20 11:37:04 +01:00
Fred Boniface 7e6568d13a Improve error handling, backend isn't providing correct data 2023-09-20 11:34:21 +01:00
3 changed files with 23 additions and 9 deletions

View File

@ -25,6 +25,7 @@ export async function fetchStaffLdb(station: string): Promise<ApiResponse<StaffL
return parseFormat(JSON.stringify(resJs));
}
// Parse dates within the JSON response
function parseFormat(jsonString: any): ApiResponse<StaffLdb> {
return JSON.parse(jsonString, (key, value) => {
if (typeof value === 'string') {

View File

@ -5,12 +5,14 @@
import { detailInit, defineDetail } from './train-detail';
import TrainDetail from './train-detail.svelte';
import { fetchStaffLdb } from './fetch';
import { error } from '@sveltejs/kit';
export let station: string;
export let title: string | undefined = 'Loading...';
export let error = {
state: false,
name: 'none'
let errorDetail = {
code: '',
message: '',
};
let detail = detailInit();
@ -29,6 +31,8 @@
title = data.data.locationName;
return data.data;
}
errorDetail.code = data.obStatus.toString() || "UNKNOWN";
errorDetail.message = data.obMsg || "An unknown error occoured";
throw new Error('Unable to Fetch Data');
}
</script>
@ -59,11 +63,17 @@
{/if}
{/if}
{:catch}
Error Loading Data
<h2>Error</h2>
<p>ERR-CODE: {errorDetail.code}</p>
<p>Message:<br>{errorDetail.message}</p>
{/await}
{#if error.state}
{#if error.name === 'unauthorized'}
<p>Error: {error.name.toLocaleUpperCase()}</p>
{/if}
{/if}
<style>
.transport-mode {
padding-top: 20px;
height: 17px;
}
.table-head-text {
color: white;
}
</style>

View File

@ -1,3 +1,4 @@
// Contains the details required to lookup train details
export interface Detail {
show: boolean;
headcode: string;
@ -5,6 +6,7 @@ export interface Detail {
uid: string;
}
// Initiates/Resets a `Detail` interface
export function detailInit(): Detail {
const detail: Detail = {
show: false,
@ -15,6 +17,7 @@ export function detailInit(): Detail {
return detail;
}
// Initiates/Updates a `Detail` interface using the given values
export function defineDetail(rid: string, uid: string, tid: string) {
const detail: Detail = {
rid: rid,