This commit is contained in:
saparatayev 2022-10-04 16:45:09 +05:00
commit 53984d8f84
6 changed files with 18 additions and 6 deletions

View File

@ -35,7 +35,9 @@ function request(method) {
.catch((error) => {
console.log("err on fetch: ", error);
const alertStore = useAlertStore();
alertStore.error(error);
if (error.code === 422) alertStore.warn(error.message);
else alertStore.error(error.message);
});
};
}
@ -60,7 +62,7 @@ async function handleResponse(response) {
?.includes("application/json");
const data = isJson ? await response.json() : null;
console.log("response data: ", response);
console.log("response data: ", response.status);
// check for error response
if (!response.ok) {
@ -71,13 +73,12 @@ async function handleResponse(response) {
}
// get error message from body or default to response status
const error = (data && data.message) || response.status;
let error = { message: "", code: 500 };
error.code = response.status;
error.message = (data && data.message) || response.status;
return Promise.reject(error);
}
// TODO: can add success messages
// alertStore.success("success");
return data;
}

View File

@ -2,11 +2,15 @@
<!-- BEGIN: Notification Content -->
<Notification refKey="customNotification" class="flex">
<CheckCircleIcon class="text-success" v-if="alertType === 'success'" />
<CheckCircleIcon class="text-amber-600" v-else-if="alertType === 'warn'" />
<XCircleIcon class="text-danger" v-else />
<div class="ml-4 mr-4">
<div v-if="alertType === 'success'" class="font-medium">
{{ $t("SUCCESS") }} !
</div>
<div v-if="alertType === 'warn'" class="font-medium">
{{ $t("WARN") }} !
</div>
<div v-else class="font-medium">{{ $t("ERROR") }} !</div>
<div class="text-slate-500 mt-1">
{{ message }}

View File

@ -123,4 +123,5 @@ export const locale = {
LEG_WARN_INFO:
"Чтобы подать документы онлайн, заполните все поля в разделах: Профиль, Контактная информация и Банковские счета",
WARN: "Warning",
};

View File

@ -123,4 +123,6 @@ export const locale = {
LEG_WARN_INFO:
"Чтобы подать документы онлайн, заполните все поля в разделах: Профиль, Контактная информация и Банковские счета",
WANR: "Предупреждение",
};

View File

@ -123,4 +123,5 @@ export const locale = {
LEG_WARN_INFO:
"Чтобы подать документы онлайн, заполните все поля в разделах: Профиль, Контактная информация и Банковские счета",
WARN: "Duýduryş",
};

View File

@ -9,6 +9,9 @@ export const useAlertStore = defineStore({
success(message) {
this.alert = { message, type: "success" };
},
warn(message) {
this.alert = { message, type: "warn" };
},
error(message) {
this.alert = { message, type: "error" };
},