fix: update useApi to return api resualt as promise in addition to set in data

This commit is contained in:
Sajad Mirjalili
2025-08-16 13:43:55 +03:30
parent f61b9ee14b
commit bbe47780e4
11 changed files with 59 additions and 97 deletions

View File

@@ -31,14 +31,16 @@ export function useApi<T, P extends any[]>(
const response = await apiFunction(...args);
setData(response.data);
return response.data;
} catch (err: unknown) {
const axisoError: AxiosError = err as AxiosError;
const axiosError: AxiosError = err as AxiosError;
console.log(axiosError);
if (axisoError.response?.status === 401) {
if (axiosError.response?.status === 401) {
navigate('/login');
}
if (axisoError.response?.status === 500) {
if (axiosError.response?.status === 500) {
toast({
message: t('messages.serverError'),
severity: 'error',