From 7960a09ee96a9f91021c13534abbfa5461cbbf81 Mon Sep 17 00:00:00 2001 From: Hal Massey Date: Fri, 19 Oct 2018 10:58:44 -0500 Subject: [PATCH] Add headers to REST error object --- lib/twitter.js | 1 + tests/rest.js | 2 ++ 2 files changed, 3 insertions(+) diff --git a/lib/twitter.js b/lib/twitter.js index 9540857e..aa315967 100644 --- a/lib/twitter.js +++ b/lib/twitter.js @@ -343,6 +343,7 @@ Twitter.prototype._doRestApiRequest = function (reqOpts, twitOptions, method, ca // place the errors in the HTTP response body into the Error object and pass control to caller var err = helpers.makeTwitError('Twitter API Error') err.statusCode = response ? response.statusCode: null; + err.headers = response ? response.headers : null; helpers.attachBodyInfoToError(err, body); callback(err, body, response); return diff --git a/tests/rest.js b/tests/rest.js index 63fcbdbf..5d95d5a9 100644 --- a/tests/rest.js +++ b/tests/rest.js @@ -638,6 +638,7 @@ describe('REST API', function () { assert(err.statusCode === 401) assert(err.code > 0) assert(err.message.match(/token/)) + assert(typeof err.headers === 'object') assert(err.twitterReply) assert(err.allErrors) assert(res) @@ -654,6 +655,7 @@ describe('REST API', function () { .catch(err => { assert(err instanceof Error) assert(err.statusCode === 401) + assert(typeof err.headers === 'object') assert(err.code > 0) assert(err.message.match(/token/)) assert(err.twitterReply)