You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Retry is great for some use-cases, but it seems like it could be extended to support custom retry scenarios.
A good example might be OAuth: if I receive a 401 Unauthorized response, I want to update my access token. Naturally, that operation is asynchronous, so it'd need a callback.
vartoken;getToken();functiongetToken(callback){oauth.getOAuthAccessToken(function(err,accessToken){if(err)returncallback&&callback(err);token=accessTokencallback&&callback(null);});}superagent.get('https://segment.io/dosomethingsecret')// superagent-oauth.sign(oauth,token)// retry once.retry(1)// this API isn't entirely feasible, it's just an example// synchronously check whether to retry.when(function(err,res){returnres&&res.unauthorized;})// only retry after this task finishes.after(1,function(next){getToken(next);}).end(onresponse);functiononresponse(err,res){// ...}
Retry is great for some use-cases, but it seems like it could be extended to support custom retry scenarios.
A good example might be OAuth: if I receive a
401 Unauthorizedresponse, I want to update my access token. Naturally, that operation is asynchronous, so it'd need a callback.