From 640a6d0cb2c06e94bdd22ed06cdbdda29d71c31d Mon Sep 17 00:00:00 2001 From: Matt Borja <3855027+mattborja@users.noreply.github.com> Date: Wed, 11 Nov 2020 04:26:56 -0700 Subject: [PATCH] Improve error handling for read-only applications (#709) Applications pending approval will return a different response body than what is presently supported. Below is a copy of the actual response that comes back in this scenario: ``` {"status":401,"rateLimitTimeout":null,"body":{"request":"/1.1/statuses/update.json","error":"Read-only application cannot POST."}} ``` Whereas the current implementation assumes the presence of an `errors` array, reading off the first element (i.e. `result.body.errors[0]`), the above scenario throws an exception as `result.body.errors` is now `undefined` and cannot be indexed). The proposed update seeks to account for this while retaining existing functionality and has been tested (error message in debug now properly says "Read-only application cannot POST." --- social/twitter/27-twitter.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/social/twitter/27-twitter.js b/social/twitter/27-twitter.js index 555d5617..ac037bee 100644 --- a/social/twitter/27-twitter.js +++ b/social/twitter/27-twitter.js @@ -642,7 +642,12 @@ module.exports = function(RED) { node.status({}); } else { node.status({fill:"red",shape:"ring",text:"twitter.status.failed"}); - node.error(result.body.errors[0].message,msg); + + if ('error' in result.body && typeof result.body.error === 'string') { + node.error(result.body.error,msg); + } else { + node.error(result.body.errors[0].message,msg); + } } }).catch(function(err) { node.status({fill:"red",shape:"ring",text:"twitter.status.failed"});