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

351
Views
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 answers
Answer question

0

Tengo la solución. Sobrepaso la propiedad statusCodesToRetry.

about 4 years ago · Juan Pablo Isaza Report
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!