Add unauthorized message
This commit is contained in:
parent
91a7d6ead3
commit
a4ba90a987
@ -1,6 +1,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import Header from '$lib/navigation/header.svelte'
|
import Header from '$lib/navigation/header.svelte'
|
||||||
import Loading from '$lib/navigation/loading.svelte';
|
import Loading from '$lib/navigation/loading.svelte';
|
||||||
|
import Island from '$lib/islands/island.svelte';
|
||||||
import Nav from '$lib/navigation/nav.svelte';
|
import Nav from '$lib/navigation/nav.svelte';
|
||||||
import { uuid } from '$lib/stores/uuid';
|
import { uuid } from '$lib/stores/uuid';
|
||||||
|
|
||||||
@ -10,6 +11,8 @@
|
|||||||
let id = ""
|
let id = ""
|
||||||
let data = [];
|
let data = [];
|
||||||
let isLoading = true;
|
let isLoading = true;
|
||||||
|
let error = false;
|
||||||
|
let errMsg = "";
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
if (id) {
|
if (id) {
|
||||||
@ -26,8 +29,11 @@
|
|||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
isLoading = true;
|
isLoading = true;
|
||||||
id = await getHeadcode() || "";
|
id = await getHeadcode() || "";
|
||||||
data = await fetchData(id);
|
const res = await fetchData(id);
|
||||||
await data; isLoading = false;
|
if (res) {
|
||||||
|
data = res;
|
||||||
|
}
|
||||||
|
isLoading = false;
|
||||||
})
|
})
|
||||||
|
|
||||||
async function fetchData(id = "") {
|
async function fetchData(id = "") {
|
||||||
@ -41,13 +47,30 @@
|
|||||||
}
|
}
|
||||||
const url = `https://owlboard.info/api/v2/timetable/train/${date}/${searchType}/${id}`
|
const url = `https://owlboard.info/api/v2/timetable/train/${date}/${searchType}/${id}`
|
||||||
const res = await fetch(url, options);
|
const res = await fetch(url, options);
|
||||||
|
isLoading = false;
|
||||||
|
if (res.status == 200) {
|
||||||
return await res.json();
|
return await res.json();
|
||||||
|
} else if (res.status === 401) {
|
||||||
|
error = true;
|
||||||
|
errMsg = "You must be logged into the staff version for this feature"
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
error = true;
|
||||||
|
errMsg = "Unable to connect, check your connection and try again"
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Header {title} />
|
<Header {title} />
|
||||||
|
|
||||||
|
{#if error}
|
||||||
|
<Island>
|
||||||
|
<p class="error">{errMsg}</p>
|
||||||
|
</Island>
|
||||||
|
{/if}
|
||||||
|
|
||||||
{#if isLoading}
|
{#if isLoading}
|
||||||
<Loading />
|
<Loading />
|
||||||
{/if}
|
{/if}
|
||||||
|
Loading…
Reference in New Issue
Block a user