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