mirror of
https://github.com/danbulant/Portfolio
synced 2026-05-24 12:35:31 +00:00
feat: typed error handling
This commit is contained in:
parent
ed51ae97d1
commit
e8328f94a3
3 changed files with 22 additions and 10 deletions
|
|
@ -1,5 +1,13 @@
|
|||
import { goto } from "$app/navigation";
|
||||
import type { AxiosError } from "axios";
|
||||
|
||||
export const API_URL = "http://localhost:8000";
|
||||
|
||||
export function errorHandler(error: { data?: { [key: string]: string[] } }, fallbackMessage: string) {
|
||||
return error?.data?.errors ? error.data.errors : { unknown: [fallbackMessage] };
|
||||
export interface ApiError {
|
||||
error: AxiosError,
|
||||
msg: string,
|
||||
}
|
||||
|
||||
export function errorHandler(error: AxiosError, msg: string): ApiError {
|
||||
return {error, msg}
|
||||
}
|
||||
|
|
@ -9,31 +9,34 @@
|
|||
import { candidateData, fetchDetails } from '../../stores/candidate';
|
||||
|
||||
|
||||
let name = "";
|
||||
let fullName = "";
|
||||
let email = "";
|
||||
|
||||
$: if ($candidateData === undefined) {
|
||||
fetch();
|
||||
} else {
|
||||
name = $candidateData.name + " " + $candidateData.surname;
|
||||
email = $candidateData.email;
|
||||
setNameEmail();
|
||||
}
|
||||
|
||||
const fetch = async () => {
|
||||
try {
|
||||
await fetchDetails();
|
||||
name = $candidateData.name + " " + $candidateData.surname;
|
||||
email = $candidateData.email;
|
||||
setNameEmail();
|
||||
} catch {
|
||||
console.error("error");
|
||||
}
|
||||
}
|
||||
|
||||
const setNameEmail = async () => {
|
||||
fullName = $candidateData.name + " " + $candidateData.surname;
|
||||
email = $candidateData.email ?? "!Nevyplněné údaje!";
|
||||
}
|
||||
</script>
|
||||
|
||||
<FullLayout>
|
||||
<div class="dashboard dashboardDesktop">
|
||||
<div class="name col-span-3">
|
||||
<DashboardInfoCard title={name}>
|
||||
<DashboardInfoCard title={fullName}>
|
||||
<span class="mt-3 text-sspsBlue truncate">{email}</span>
|
||||
<span class="mt-3 text-sspsGray text-xs">Uchazeč na SSPŠ</span>
|
||||
</DashboardInfoCard>
|
||||
|
|
@ -50,8 +53,8 @@
|
|||
</div>
|
||||
<div class="dashboard dashboardMobile">
|
||||
<div class="my-10 name w-[90%] mx-auto">
|
||||
<DashboardInfoCard title={name}>
|
||||
<span class="mt-3 text-sspsBlue truncate">{name}</span>
|
||||
<DashboardInfoCard title={fullName}>
|
||||
<span class="mt-3 text-sspsBlue truncate">{fullName}</span>
|
||||
<span class="mt-3 text-sspsGray text-xs">Uchazeč na SSPŠ</span>
|
||||
</DashboardInfoCard>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { apiFetchDetails, apiFillDetails, apiLogin, apiLogout } from "../api/candidate";
|
||||
import { writable } from "svelte/store";
|
||||
import type { ApiError } from "src/api";
|
||||
|
||||
export interface CandidateData {
|
||||
name?: string;
|
||||
|
|
|
|||
Loading…
Reference in a new issue