Skip to content

Commit 02e480d

Browse files
Fix error throw parameter on doRequest (#353)
* Fix error throw parameter on doRequest * stringfied error for more versatile objects, modified tests accordingly Co-authored-by: Bruce Martin <[email protected]>
1 parent 22bd071 commit 02e480d

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/jira.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ export default class JiraApi {
303303

304304
return response;
305305
} catch (e) {
306-
throw new Error(e);
306+
throw new Error(JSON.stringify(e));
307307
}
308308
}
309309

test/jira-tests.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -299,35 +299,34 @@ describe('Jira API Tests', () => {
299299
it('doRequest throws an error properly', async () => {
300300
// eslint-disable-next-line no-underscore-dangle
301301
const revert = JiraApi.__set__('_request', (uri, options, callback) => {
302-
callback(undefined, {
303-
body: {
302+
callback({
303+
body: JSON.stringify({
304304
errorMessages: ['some error to throw'],
305-
},
305+
}),
306306
});
307307
});
308308

309309
const jira = new JiraApi(getOptions());
310310

311311
await jira.doRequest({})
312-
.should.eventually.be.rejectedWith('some error to throw');
312+
.should.eventually.be.rejectedWith('{"body":"{\\"errorMessages\\":[\\"some error to throw\\"]}"}');
313313

314314
revert();
315315
});
316316

317317
it('doRequest throws a list of errors properly', async () => {
318318
// eslint-disable-next-line no-underscore-dangle
319319
const revert = JiraApi.__set__('_request', (uri, options, callback) => {
320-
callback(undefined, {
321-
body: {
322-
errorMessages: ['some error to throw', 'another error'],
323-
},
320+
callback({
321+
body:
322+
JSON.stringify({ errorMessages: ['some error to throw', 'another error'] }),
324323
});
325324
});
326325

327326
const jira = new JiraApi(getOptions());
328327

329328
await jira.doRequest({})
330-
.should.eventually.be.rejectedWith('some error to throw, another error');
329+
.should.eventually.be.rejectedWith('{"body":"{\\"errorMessages\\":[\\"some error to throw\\",\\"another error\\"]}"}');
331330

332331
revert();
333332
});

0 commit comments

Comments
 (0)