Permalink
Browse files

Handle reauthing on 403 properly

  • Loading branch information...
isaacs committed Feb 11, 2013
1 parent d9a2a16 commit 39c2c460aae9cda31638300009fdc78943444df7
Showing with 7 additions and 4 deletions.
  1. +7 −4 lib/request.js
View
@@ -8,7 +8,8 @@ var url = require("url")
, request = require("request")
, retry = require("retry")
-function regRequest (method, where, what, etag, nofollow, cb_) {
+function regRequest (method, where, what, etag, nofollow, reauthed, cb_) {
+ if (typeof cb_ !== "function") cb_ = reauthed, reauthed = false
if (typeof cb_ !== "function") cb_ = nofollow, nofollow = false
if (typeof cb_ !== "function") cb_ = etag, etag = null
if (typeof cb_ !== "function") cb_ = what, what = null
@@ -84,7 +85,7 @@ function regRequest (method, where, what, etag, nofollow, cb_) {
this.conf.set('_token', this.couchLogin.token)
return regRequest.call(this,
method, where, what,
- etag, nofollow, cb_)
+ etag, nofollow, reauthed, cb_)
}.bind(this))
}
}
@@ -110,7 +111,6 @@ function regRequest (method, where, what, etag, nofollow, cb_) {
})
var self = this
- var reauthed = false;
operation.attempt(function (currentAttempt) {
self.log.info("trying", "registry request attempt " + currentAttempt
+ " at " + (new Date()).toLocaleTimeString())
@@ -129,14 +129,17 @@ function regRequest (method, where, what, etag, nofollow, cb_) {
( statusCode === 401 ||
statusCode === 400 ||
statusCode === 403 )
+ if (reauth)
+ reauthed = true
var timeout = statusCode === 408
var serverError = statusCode >= 500
var statusRetry = !statusCode || timeout || serverError
if (reauth && this.conf.get('_auth') && this.conf.get('_token')) {
this.conf.del('_token')
this.couchLogin.token = null
- return regRequest.call(this, method, where, what, etag, nofollow, cb_)
+ return regRequest.call(this, method, where, what,
+ etag, nofollow, reauthed, cb_)
}
if (er && statusRetry && operation.retry(er)) {
self.log.info("retry", "will retry, error on last attempt: " + er)

0 comments on commit 39c2c46

Please sign in to comment.