با سلام. من سرویس axios رو در توابعی نوشتم که تمام درخواستها رو هندل میکنه. بطور مثال در کد زیر درخواست get ارسال میشه. چطور میتونم هوک authDispatch رو صدا بزنم در صورتی که get تنها یک تابع ساده هس؟
const get = async (uri) => {
const url = BaseUrl + uri
try {
const accessToken = localStorage.getItem('access_token');
const response = await axios.get(url, {
headers: { Authorization: `Bearer ${accessToken}` }
});
return response.data;
} catch (error) {
if (error.response && error.response.status == '401') {
authDispatch({ type: actionTypes.LOGOUT });
notify('Log in to your account', 'info')
}
else if (error.response && error.response.status == '403') {
notify('Permission denied', 'error')
}
else if (error.response && error.response.status == '404') {
notify('Not found', 'error')
}
else if (error.message === 'Network Error') {
notify('Connection error', 'error');
}
throw error;
}
};