Skip to content

Commit 9193104

Browse files
committed
Throw error on failed request
1 parent da21f86 commit 9193104

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/jira.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ function request(uri, options) {
77
if (err) {
88
reject(err);
99
} else {
10+
if (httpResponse.statusCode >= 400) {
11+
reject(httpResponse.body);
12+
}
13+
1014
// for compatibility with request-promise
1115
resolve(httpResponse.body);
1216
}
@@ -285,15 +289,19 @@ export default class JiraApi {
285289
...requestOptions,
286290
};
287291

288-
const response = await this.request(options);
292+
try {
293+
const response = await this.request(options);
289294

290-
if (response) {
291-
if (Array.isArray(response.errorMessages) && response.errorMessages.length > 0) {
292-
throw new Error(response.errorMessages.join(', '));
295+
if (response) {
296+
if (Array.isArray(response.errorMessages) && response.errorMessages.length > 0) {
297+
throw new Error(response.errorMessages.join(', '));
298+
}
293299
}
294-
}
295300

296-
return response;
301+
return response;
302+
} catch (e) {
303+
throw new Error(e);
304+
}
297305
}
298306

299307
/**

0 commit comments

Comments
 (0)