Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch Requests fail to refresh access token #99

Closed
abecks opened this issue Oct 28, 2013 · 2 comments
Closed

Batch Requests fail to refresh access token #99

abecks opened this issue Oct 28, 2013 · 2 comments
Assignees
Labels
🚨 This issue needs some love. triage me I really want to be triaged.

Comments

@abecks
Copy link

abecks commented Oct 28, 2013

I noticed that while making batch requests, 401 Unauthorized responses are not caught in the current handler because they return an HTTP status code of 200, and each error is presented in a JSON array in the response body.

I managed to temporarily fix this by changing the OAuth2Client.prototype.request function:

from:

var hasAuthError = (res.statusCode == 401 || res.statusCode == 403)

to:

// TODO: Check if it's not userRateLimitExceeded
var hasAuthError = 
    (res.statusCode == 401 || res.statusCode == 403)
    || body.indexOf('401 Unauthorized') >= 0; // batch requests

A deep copy of the request options must be cached:

from:

var that = this;
var credentials = this.credentials;

to:

var optsClone = JSON.parse(JSON.stringify(opts)); 
var that = this;
var credentials = this.credentials;

and used for the request when it is re-played

from:

var tokens = result;
tokens.refresh_token = credentials.refresh_token;
that.credentials = tokens;
that.request(opts, opt_callback, true);

to:

var tokens = result;
tokens.refresh_token = credentials.refresh_token;
that.credentials = tokens;
that.request(optsClone, opt_callback, true);

I'm sure there is probably a more elegant way of fixing this instead of using "indexOf", but this should help people having the same problem for now.

@rakyll
Copy link
Contributor

rakyll commented Oct 30, 2013

OData batches implemented by this client library is quite experimental. As long as, I don't have a native http implementation to parse the multipart segments, batch requests are not that useful at all. So, I'm on hold for now to fix known error handling issues with batch requests.

@ryanseys
Copy link
Contributor

Closing as WONTFIX. In version 1.0.0 we have removed support for batch requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚨 This issue needs some love. triage me I really want to be triaged.
Projects
None yet
Development

No branches or pull requests

4 participants