Hi,
It's okay to not use timeout.
In this case, if you receive 400 or 500 status, it will automatically retry the request.
However, please note that those response are considered error, so it will be catched.
To handle 400 or 500 status, put your logic after catch(error)
constrax=require('retry-axios');constaxios=require('axios');rax.attach();constmyRequest=async()=>{try{constmyConfig={raxConfig:{retry:5,// number of retry when facing 400 or 500onRetryAttempt:err=>{constcfg=rax.getConfig(err);console.log(`Retry attempt #${cfg.currentRetryAttempt}`);// track current trial}},}constreq=awaitaxios.get('https://mock.codes/500',myConfig);console.log(req.data);}catch(error){// 400 or 500 response will be handled hereconsole.log(error.response.status);// continue your code here ...}}myRequest();
Hope this helps.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi, If I dont want use the timeout , I just do the retries when my api have a error status 400 or 500. it can work?. because dont work me
Hi,
It's okay to not use timeout.
In this case, if you receive
400or500status, it will automatically retry the request.However, please note that those response are considered
error, so it will be catched.To handle
400or500status, put your logic aftercatch(error)Hope this helps.