Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
Re-auth on a 401 status
Browse files Browse the repository at this point in the history
Re: isaacs/npm#2631
  • Loading branch information
isaacs committed Jul 17, 2012
1 parent 595733a commit 5f987a5
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/request.js
Expand Up @@ -114,14 +114,22 @@ function regRequest (method, where, what, etag, nofollow, cb_) {
, function (er, parsed, raw, response) {
// Only retry on 408, 5xx or no `response`.
var statusCode = response && response.statusCode
var statusRetry = !statusCode || (statusCode === 408 || statusCode >= 500)
var reauth = statusCode === 401
var timeout = statusCode === 408
var serverError = statusCode >= 500
var statusRetry = !statusCode || timeout || serverError
if (reauth && this.auth && this.token) {
this.token = null
this.couchLogin.token = null
return regRequest.call(this, method, where, what, etag, nofollow, cb_)
}
if (er && statusRetry && operation.retry(er)) {
self.log.info("retry", "will retry, error on last attempt: " + er)
return
}
cb.apply(null, arguments)
})
})
}.bind(this))
}.bind(this))
}

function makeRequest (method, remote, where, what, etag, nofollow, tok, cb_) {
Expand Down

0 comments on commit 5f987a5

Please sign in to comment.