Skip to content

Commit 96b7859

Browse files
author
Stefano Sala
committed
Catch -1 body or response
1 parent 13dae16 commit 96b7859

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

lib/request.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Request {
4242
return oauth.authorize(req);
4343
}
4444

45-
error(message, response, body, error) {
45+
error(message, response, error) {
4646
if (!error) error = new Error(message);
4747
error.response = {
4848
statusCode: response.statusCode
@@ -98,10 +98,20 @@ class Request {
9898
return;
9999
}
100100

101+
if (response === -1 || body === -1) {
102+
const msg = 'A meaningless error has occurred, returning -1. ' +
103+
'This could be the result of an incorrect folder setup.';
104+
const error = this.error(msg, response);
105+
logger.error(msg);
106+
reject(error);
107+
cb(error, body, response);
108+
return;
109+
}
110+
101111
// Handle error codes between 400 & 600
102112
if (response.statusCode >= 400 && response.statusCode < 600) {
103113
const msg = `Request failed with code: ${response.statusCode}`;
104-
const error = this.error(msg, response, body);
114+
const error = this.error(msg, response);
105115

106116
logger.error(msg);
107117
reject(error);
@@ -127,7 +137,7 @@ class Request {
127137

128138
if (json.hasOwnProperty('error') || json.hasOwnProperty('errors')) {
129139
const errorMessage = json.error || JSON.stringify(json.errors);
130-
const serverError = this.error(errorMessage, response, body);
140+
const serverError = this.error(errorMessage, response);
131141
cb(serverError, body, response);
132142
reject(serverError);
133143
return;
@@ -140,7 +150,7 @@ class Request {
140150
} catch (e) {
141151

142152
const malformedMsg = `Error parsing response body: ${e.message || e}`;
143-
const malformedError = this.error(malformedMsg, body, response, e);
153+
const malformedError = this.error(malformedMsg, response, e);
144154

145155
logger.error(malformedMsg);
146156
cb(malformedError, body, response);

0 commit comments

Comments
 (0)