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