Refactor axios error handling to throw new Error instances for better stack trace clarity; update component lifecycle methods in AccountPage, ListsPage, and ListDetailPage to use void for asynchronous calls; adjust polling interval type in ListDetailPage for improved type safety.

This commit is contained in:
mohamad 2025-05-08 23:28:33 +02:00
parent 0dbee3bb4b
commit 4283fe8a19
5 changed files with 12 additions and 16 deletions

View File

@ -1,6 +1,6 @@
import { boot } from 'quasar/wrappers'; import { boot } from 'quasar/wrappers';
import axios, { AxiosInstance } from 'axios'; import axios from 'axios';
import { API_BASE_URL, API_VERSION, API_ENDPOINTS } from 'src/config/api-config'; import { API_BASE_URL } from 'src/config/api-config';
// Create axios instance // Create axios instance
const api = axios.create({ const api = axios.create({
@ -20,7 +20,7 @@ api.interceptors.request.use(
return config; return config;
}, },
(error) => { (error) => {
return Promise.reject(error); return Promise.reject(new Error(String(error)));
} }
); );
@ -56,11 +56,11 @@ api.interceptors.response.use(
localStorage.removeItem('token'); localStorage.removeItem('token');
localStorage.removeItem('refreshToken'); localStorage.removeItem('refreshToken');
window.location.href = '/login'; window.location.href = '/login';
return Promise.reject(refreshError); return Promise.reject(new Error(String(refreshError)));
} }
} }
return Promise.reject(error); return Promise.reject(new Error(String(error)));
} }
); );

View File

@ -259,6 +259,6 @@ const onPreferenceChange = async () => {
}; };
onMounted(() => { onMounted(() => {
fetchProfile(); void fetchProfile();
}); });
</script> </script>

View File

@ -35,7 +35,6 @@
import { ref, onMounted, computed } from 'vue'; import { ref, onMounted, computed } from 'vue';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import { apiClient, API_ENDPOINTS } from 'src/config/api'; import { apiClient, API_ENDPOINTS } from 'src/config/api';
import { useAuthStore } from 'stores/auth';
import { copyToClipboard, useQuasar } from 'quasar'; import { copyToClipboard, useQuasar } from 'quasar';
interface Group { interface Group {
@ -52,7 +51,6 @@ const props = defineProps({
}); });
const route = useRoute(); const route = useRoute();
const authStore = useAuthStore();
const $q = useQuasar(); const $q = useQuasar();
const group = ref<Group | null>(null); const group = ref<Group | null>(null);

View File

@ -245,13 +245,11 @@ const list = ref<List>({
const loading = ref(true); const loading = ref(true);
const error = ref<string | null>(null); const error = ref<string | null>(null);
const addingItem = ref(false); const addingItem = ref(false);
const pollingInterval = ref<ReturnType<typeof setInterval> | undefined>(undefined); const pollingInterval = ref<NodeJS.Timeout | null>(null);
const lastListUpdate = ref<string | null>(null); const lastListUpdate = ref<string | null>(null);
const lastItemUpdate = ref<string | null>(null); const lastItemUpdate = ref<string | null>(null);
const newItem = ref<{ name: string; quantity?: string }>({ name: '' }); const newItem = ref<{ name: string; quantity?: string }>({ name: '' });
const editingItemName = ref('');
const editingItemQuantity = ref<string | undefined>(undefined);
// OCR related state // OCR related state
const showOcrDialog = ref(false); const showOcrDialog = ref(false);
@ -323,13 +321,13 @@ const checkForUpdates = async () => {
const startPolling = () => { const startPolling = () => {
// Poll every 15 seconds // Poll every 15 seconds
pollingInterval.value = setInterval(checkForUpdates, 15000); pollingInterval.value = setInterval(() => void checkForUpdates(), 15000);
}; };
const stopPolling = () => { const stopPolling = () => {
if (pollingInterval.value) { if (pollingInterval.value) {
clearInterval(pollingInterval.value); clearInterval(pollingInterval.value);
pollingInterval.value = undefined; pollingInterval.value = null;
} }
}; };

View File

@ -196,9 +196,9 @@ const fetchLists = async () => {
}; };
onMounted(() => { onMounted(() => {
fetchLists(); void fetchLists();
fetchGroups(); void fetchGroups();
fetchGroupName(); void fetchGroupName();
}); });
const filteredLists = computed(() => { const filteredLists = computed(() => {