Merge branch 'develop' into chore/token

This commit is contained in:
SajadMRjl
2025-08-16 16:04:56 +03:30
committed by GitHub
15 changed files with 56 additions and 503 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',
@@ -56,8 +58,7 @@ export function useApi<T, P extends any[]>(
// If the 'immediate' option is true, execute the function on mount
useEffect(() => {
if (options.immediate) {
// We pass undefined as params for the initial call.
execute(...(undefined as unknown as P));
execute(...([] as unknown as P)); // safe default: no args
}
}, [execute, options.immediate]);