Enhance error handling in useDataStore by adding skipErrorForStatuses option to bypass specific status codes in CheckApiError. This improves error management and allows for more flexible API response handling.

This commit is contained in:
burakovec
2026-03-26 12:38:43 +03:00
parent 2ecda61ad4
commit 2bbb30525e

View File

@ -64,6 +64,8 @@ export const useDataStore = defineStore('dataStore', () => {
options?: Record<string, any>
toast?: Record<string, any>
full?: boolean
/** Bu status kodları için CheckApiError atlanır, hata objesi döner */
skipErrorForStatuses?: number[]
} = {}
): Promise<any> => {
try {
@ -86,7 +88,11 @@ export const useDataStore = defineStore('dataStore', () => {
return response.data
}
} catch (error: any) {
CheckApiError(error.response?.status, error.response?.data)
const status = error.response?.status
if (data.skipErrorForStatuses?.includes(status)) {
return { _error: true, status, data: error.response?.data }
}
CheckApiError(status, error.response?.data)
console.error('Hata oluştu:', error)
return Promise.resolve('errorfalse')
}