fix(api.tsx): remove unnecessary try-catch block and add error logging for better debugging

fix(index.ts): remove console.log statement for error logging
This commit is contained in:
anovazzi1 2023-10-05 18:04:21 -03:00 committed by anovazzi1
commit 0b1f837c2a
2 changed files with 8 additions and 7 deletions

View file

@ -31,13 +31,11 @@ function ApiInterceptor() {
logout();
navigate("/login");
}
const res = await renewAccessToken(refreshToken);
if (res?.data?.access_token && res?.data?.refresh_token) {
login(res?.data?.access_token, res?.data?.refresh_token);
}
try {
const res = await renewAccessToken(refreshToken);
if (res?.data?.access_token && res?.data?.refresh_token) {
login(res?.data?.access_token, res?.data?.refresh_token);
}
if (error?.config?.headers) {
delete error.config.headers["Authorization"];
error.config.headers["Authorization"] = `Bearer ${cookies.get(
@ -50,6 +48,10 @@ function ApiInterceptor() {
if (axios.isAxiosError(error) && error.response?.status === 401) {
logout();
navigate("/login");
} else {
console.error(error);
logout();
navigate("/login");
}
}
}

View file

@ -399,7 +399,6 @@ export async function renewAccessToken(token: string) {
return await api.post(`${BASE_URL_API}refresh?token=${token}`);
}
} catch (error) {
console.log("Error:", error);
throw error;
}
}