Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

341
Vistas
axios-retry no funciona para la respuesta con el estado 4XX

Estoy usando axios para llamadas api. ¡En caso de que ocurra alguna falla o estado de respuesta! = 200, necesito volver a intentar la llamada api. Por defecto, reintentar axios funciona para el estado con 5XX. Pero según la documentación, podemos anular retryCondition según nuestros requisitos.

Aquí está mi fragmento de código

 export const doApiFetchCall = (apiEndPoint, dataPayLoad, config, axiosObject, callType,caller,timeoutParam,retryCount) => { let instance = undefined; if(axiosObject === 'axios') { instance = localAxios; } else if(axiosObject === 'axiosProxy') { instance = localAxiosProxy; } else if (axiosObject === 'axiosProxyJira') { instance = localAxiosProxyJira; } let restOptions = { url: apiEndPoint, method: callType, timeout: timeoutParam || 20000, // timeout in ms headers:config.headers||null, raxConfig: { retry: retryCount || 0, // number of retry when facing 4xx or 5xx instance: instance, retryCondition: () => true, onRetryAttempt: err => { let tempError = Object.assign({}, err)//{...err} const cfg = rax.getConfig(err); delete tempError.config; delete tempError.request; }, noResponseRetries: 3, // number of retry when facing connection error httpMethodsToRetry: ['GET', 'HEAD', 'OPTIONS', 'DELETE', 'PUT', 'POST', 'PATCH'], retryDelay: 3000, backoffType: 'static' } }; var caller_id = caller||''; if (dataPayLoad) restOptions = {...restOptions, data: dataPayLoad}; return new Promise((resolve, reject) => { instance(restOptions) .then(response => { logger.info(caller_id, '[API_CALL_SUCCESS] API call has succeeded'); if (response) { const {status, data} = response; logger.info(caller_id, '[API_CALL_SUCCESS] API call Status Code: [' + status + ']'); try { if (status === 200 || status === 201) { resolve(response); } else { reject(null); } } catch (jsonParseError) { reject(jsonParseError); } } else { resolve(null); } }) .catch(error => { const {response, request, message, config} = error; reject(error); });

He anulado la condición de reintento. No estoy seguro de si se hizo de la manera correcta. ¿Puede alguien por favor decirme qué mal estoy haciendo?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Tengo la solución. Sobrepaso la propiedad statusCodesToRetry.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda