From 077a46433073445be0b44bf1cd3d99d0def846a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Fern=C3=A1ndez?= Date: Mon, 4 May 2015 11:25:09 +0200 Subject: [PATCH] Workaround for superagent issue setting body to null See more here: https://github.com/visionmedia/superagent/pull/638 --- lib/auth.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/auth.js b/lib/auth.js index 29e8b48..a8fc0f3 100644 --- a/lib/auth.js +++ b/lib/auth.js @@ -176,8 +176,18 @@ module.exports = { }, _onAuthResponse: function(callback, grantType, url, err, res) { + var responseData = res.body; + + /* + * Handling superagent issue setting body to null, see more here: + * https://github.com/visionmedia/superagent/pull/638 + */ + if (responseData === null) { + responseData = JSON.parse(res.text); + } + if (res.ok && !err) { - callback(null, res.body); + callback(null, responseData); } else { callback(new PodioErrors.PodioAuthorizationError('Authentication for ' + grantType + ' failed. Reason: ' + res.body.error_description, res.status, url), void 0); }