added timeout and message to axios
This commit is contained in:
+20
-15
@@ -8,7 +8,9 @@ export default defineNuxtPlugin(() => {
|
||||
const { token, logout } = useAuth();
|
||||
|
||||
const axios = axiosOriginal.create({
|
||||
baseURL: config.public.API_BASE_URL
|
||||
timeout: 30000,
|
||||
timeoutErrorMessage: "فرآیند بیش از حد انتظار طول کشید",
|
||||
baseURL: config.public.API_BASE_URL,
|
||||
});
|
||||
|
||||
axios.interceptors.request.use((config) => {
|
||||
@@ -16,29 +18,32 @@ export default defineNuxtPlugin(() => {
|
||||
!config.url?.includes(API_ENDPOINTS.auth.signin) &&
|
||||
!config.url?.includes(API_ENDPOINTS.account.send_otp)
|
||||
) {
|
||||
config.headers.Authorization = token.value ? `Bearer ${token.value}` : undefined;
|
||||
config.headers.Authorization = token.value
|
||||
? `Bearer ${token.value}`
|
||||
: undefined;
|
||||
}
|
||||
|
||||
return config;
|
||||
});
|
||||
|
||||
axios.interceptors.response.use((response) => {
|
||||
return response;
|
||||
}, async function(error) {
|
||||
axios.interceptors.response.use(
|
||||
(response) => {
|
||||
return response;
|
||||
},
|
||||
async function (error) {
|
||||
await Logger.axiosErrorLog(error);
|
||||
|
||||
await Logger.axiosErrorLog(error);
|
||||
// if (error.status === 401) {
|
||||
// logout();
|
||||
// }
|
||||
|
||||
// if (error.status === 401) {
|
||||
// logout();
|
||||
// }
|
||||
|
||||
return Promise.reject(error);
|
||||
});
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
return {
|
||||
provide: {
|
||||
axios
|
||||
}
|
||||
axios,
|
||||
},
|
||||
};
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user