You've already forked isop-mirror
fix: simplify error handling for FetchError in various components
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user