Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

455
Views
Cómo dirigir el error > 500 con Axios Interceptor

Cómo dirigir la respuesta de error con Axios Interceptor. ¡Usé el interceptor axios para todas las solicitudes http!

la expectativa es que cuando el error del servidor 500, 501, etc., sea redirigido a la ruta "/500"

 export const request = axios.create({ baseURL: BASE_URL_API }); request.interceptors.request.use( async (config: AxiosRequestConfig) => { try { const token = GetCookie('token'); config.headers = { Authorization: `Bearer ${token}`, }; return config; } catch (errorConfig) { return Promise.reject(errorConfig); } }, error => { return Promise.reject(error); }, ); // Add a response interceptor request.interceptors.response.use( response => { return response; }, async (error: AxiosError) => { const status = error.response?.status; try { if (status === 401 && error.response?.data.error.message === "Full authentication is required to access this resource" ) { RemoveCookie('token') RemoveCookie('_currentUser') window.location.href = '/'; } else { return Promise.reject(error); } return Promise.reject(error); } catch (errorValue) { return Promise.reject(errorValue); } }, );
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!