You've already forked isop-mirror
fix: simplify error handling for FetchError in various components
This commit is contained in:
@@ -43,7 +43,7 @@ async function handleLogin() {
|
||||
|
||||
success.value = true;
|
||||
} catch (e) {
|
||||
if (e instanceof FetchError && e.response?.status === 422) {
|
||||
if (e instanceof FetchError) {
|
||||
error.value = e.response?._data.message;
|
||||
}
|
||||
} finally {
|
||||
|
||||
@@ -33,7 +33,7 @@ async function handleUpdateOfBasicInfo(internship: NewInternship) {
|
||||
|
||||
navigateTo("/dashboard/admin/internships");
|
||||
} catch (e) {
|
||||
if (e instanceof FetchError && (e.response?.status === 422 || e.response?.status === 400)) {
|
||||
if (e instanceof FetchError) {
|
||||
action_error.value = e.response?._data.message;
|
||||
}
|
||||
} finally {
|
||||
|
||||
@@ -64,7 +64,6 @@ async function saveChanges() {
|
||||
navigateTo("/dashboard/admin/students");
|
||||
} catch (e) {
|
||||
if (e instanceof FetchError) {
|
||||
console.error('Error saving student:', e.response?._data.message);
|
||||
alert('Chyba:\n' + e.response?._data.message);
|
||||
}
|
||||
} finally {
|
||||
@@ -111,8 +110,6 @@ const deleteStudent = async () => {
|
||||
} catch (e) {
|
||||
if (e instanceof FetchError) {
|
||||
deleteError.value = e.response?._data?.message || 'Chyba pri mazaní študenta.';
|
||||
} else {
|
||||
deleteError.value = 'Neznáma chyba pri mazaní študenta.';
|
||||
}
|
||||
} finally {
|
||||
deleteLoading.value = false;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import type { NewInternship } from '~/types/internships';
|
||||
import { FetchError } from 'ofetch';
|
||||
|
||||
definePageMeta({
|
||||
middleware: ['sanctum:auth', 'student-only'],
|
||||
@@ -25,8 +26,10 @@ async function handleInternshipRegistration(internship: NewInternship) {
|
||||
});
|
||||
|
||||
navigateTo("/dashboard/student");
|
||||
} catch (e: any) {
|
||||
error.value = e.data?.message as string;
|
||||
} catch (e) {
|
||||
if (e instanceof FetchError) {
|
||||
error.value = e.response?._data.message;
|
||||
}
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ async function handleLogin() {
|
||||
try {
|
||||
await login(form.value);
|
||||
} catch (e) {
|
||||
if (e instanceof FetchError && e.response?.status === 422) {
|
||||
if (e instanceof FetchError) {
|
||||
error.value = e.response?._data.message;
|
||||
}
|
||||
} finally {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { NewRole } from '~/types/role';
|
||||
import type { NewUser } from '~/types/user';
|
||||
import { FetchError } from 'ofetch';
|
||||
|
||||
definePageMeta({
|
||||
middleware: ['sanctum:guest'],
|
||||
@@ -63,8 +64,10 @@ async function handleRegistration() {
|
||||
});
|
||||
|
||||
navigateTo("/");
|
||||
} catch (e: any) {
|
||||
error.value = e.data?.message as string;
|
||||
} catch (e) {
|
||||
if (e instanceof FetchError) {
|
||||
error.value = e.response?._data.message;
|
||||
}
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { NewRole } from '~/types/role';
|
||||
import type { NewUser } from '~/types/user';
|
||||
import { FetchError } from 'ofetch';
|
||||
|
||||
definePageMeta({
|
||||
middleware: ['sanctum:guest'],
|
||||
@@ -71,8 +72,10 @@ async function handleRegistration() {
|
||||
});
|
||||
|
||||
navigateTo("/");
|
||||
} catch (e: any) {
|
||||
error.value = e.data?.message as string;
|
||||
} catch (e) {
|
||||
if (e instanceof FetchError) {
|
||||
error.value = e.response?._data.message;
|
||||
}
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { FetchError } from 'ofetch';
|
||||
|
||||
const client = useSanctumClient();
|
||||
|
||||
definePageMeta({
|
||||
@@ -36,8 +38,10 @@ async function handleReset() {
|
||||
});
|
||||
|
||||
navigateTo("/reset_psw/request_sent");
|
||||
} catch (e: any) {
|
||||
error.value = e.data?.message as string;
|
||||
} catch (e) {
|
||||
if (e instanceof FetchError) {
|
||||
error.value = e.response?._data.message;
|
||||
}
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user