Skip to content

Commit

Permalink
Fix processing of response from authURL if body is a buffer, and impr…
Browse files Browse the repository at this point in the history
…ove error handling in case of unexpected response
  • Loading branch information
paddybyers committed Jun 29, 2015
1 parent 4c734ac commit 93b658b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions common/lib/client/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,16 @@ var Auth = (function() {
tokenRequestCallback = function(params, cb) {
var authHeaders = Utils.mixin({accept: 'application/json'}, authOptions.authHeaders);
Http.getUri(rest, authOptions.authUrl, authHeaders || {}, Utils.mixin(params, authOptions.authParams), function(err, body, headers, unpacked) {
if(err) return cb(err);
if(!unpacked && headers['content-type'] !== 'text/plain') body = JSON.parse(body);
if(err || unpacked) return cb(err, body);
if(BufferUtils.isBuffer(body)) body = body.toString();
if(headers['content-type'] == 'application/json') {
try {
body = JSON.parse(body);
} catch(e) {
cb(new ErrorInfo('Unexpected error processing authURL response; err = ' + e.message, 40000, 400));
return;
}
}
cb(null, body);
});
};
Expand Down

0 comments on commit 93b658b

Please sign in to comment.