Merge branch 'develop' into chore/token
This commit is contained in:
@@ -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]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user