fix: alert i18n dialog

This commit is contained in:
puriphatt 2024-06-17 04:00:22 +00:00
parent 3aa99f2ede
commit 8fdc916955
5 changed files with 17 additions and 6 deletions

View file

@ -21,10 +21,10 @@ const api = axios.create({ baseURL: import.meta.env.VITE_API_BASE_URL });
function parseError(
status: number,
body?: { status: number; message: string },
body?: { status: number; message: string; code: string },
) {
if (status === 422) return 'ข้อมูลไม่ถูกต้อง กรุณาตรวจสอบใหม่อีกครั้ง';
if (body && body.message) return body.message;
if (body && body.code) return body.code;
return 'เกิดข้อผิดพลาดทำให้ระบบไม่สามารถทำงานได้ กรุณาลองใหม่ในภายหลัง';
}
@ -43,11 +43,17 @@ api.interceptors.response.use(
(err) => {
useLoader().hide();
dialog({
color: 'negative',
color:
err.response.status >= 400 && err.response.status < 500
? 'warning'
: 'negative',
icon: 'mdi-alert',
title: 'เกิดข้อผิดพลาด',
actionText: 'ตกลง',
title:
err.response.status >= 400 && err.response.status < 500
? 'warning'
: 'errorOccurred',
persistent: true,
enablei18n: true,
message: parseError(err.response.status, err.response.data),
action: () => {},
});