From 48a5c15b9d8a466676c4b069a0e67b41f4b5c14c Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 13 Sep 2024 10:54:09 +0200 Subject: [PATCH] feat: refs #7828 create axios instance which no manage errors --- src/boot/axios.js | 8 ++++++-- src/pages/Worker/Card/WorkerTimeControl.vue | 6 ++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/boot/axios.js b/src/boot/axios.js index 9b32275bd..99a163cca 100644 --- a/src/boot/axios.js +++ b/src/boot/axios.js @@ -5,8 +5,10 @@ import useNotify from 'src/composables/useNotify.js'; const session = useSession(); const { notify } = useNotify(); +const baseUrl = '/api/'; -axios.defaults.baseURL = '/api/'; +axios.defaults.baseURL = baseUrl; +const axiosNoError = axios.create({ baseURL: baseUrl }); const onRequest = (config) => { const token = session.getToken(); @@ -79,5 +81,7 @@ const onResponseError = (error) => { axios.interceptors.request.use(onRequest, onRequestError); axios.interceptors.response.use(onResponse, onResponseError); +axiosNoError.interceptors.request.use(onRequest); +axiosNoError.interceptors.response.use(onResponse); -export { onRequest, onResponseError }; +export { onRequest, onResponseError, axiosNoError }; diff --git a/src/pages/Worker/Card/WorkerTimeControl.vue b/src/pages/Worker/Card/WorkerTimeControl.vue index 3893305a5..9ae91f8ce 100644 --- a/src/pages/Worker/Card/WorkerTimeControl.vue +++ b/src/pages/Worker/Card/WorkerTimeControl.vue @@ -2,6 +2,7 @@ import { useI18n } from 'vue-i18n'; import { useRoute } from 'vue-router'; import { onMounted, ref, computed, onBeforeMount, nextTick, reactive } from 'vue'; +import { axiosNoError } from 'src/boot/axios'; import FetchData from 'components/FetchData.vue'; import WorkerTimeHourChip from 'pages/Worker/Card/WorkerTimeHourChip.vue'; @@ -266,10 +267,11 @@ const fetchWeekData = async () => { }; try { const mail = ( - await axios.get(`Workers/${route.params.id}/mail`, { + await axiosNoError.get(`Workers/${route.params.id}/mail`, { params: { filter: { where } }, }) ).data[0]; + if (!mail) state.value = null; else { state.value = mail.state; @@ -277,7 +279,7 @@ const fetchWeekData = async () => { } canResend.value = !!( - await axios.get('WorkerTimeControlMails/count', { params: { where } }) + await axiosNoError.get('WorkerTimeControlMails/count', { params: { where } }) ).data.count; } catch (err) { console.error('Error fetching week data');