-
Notifications
You must be signed in to change notification settings - Fork 511
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:adds details to rest exception (#565)
- Loading branch information
Showing
3 changed files
with
59 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
var RestException = require('../../../lib/base/RestException'); | ||
|
||
describe('exception gets created from string', function () { | ||
it('should test serialize without details', function () { | ||
const response = { | ||
statusCode: 200, | ||
body: '{"message":"test", "code":81022,"more_info": "https://www.twilio.com/docs/errors/81022"}', | ||
}; | ||
const exception = new RestException(response); | ||
expect(exception.status).toEqual(200); | ||
expect(exception.message).toEqual('test'); | ||
expect(exception.code).toEqual(81022); | ||
expect(exception.moreInfo).toEqual('https://www.twilio.com/docs/errors/81022'); | ||
}); | ||
}); | ||
|
||
describe('exception gets created from json error', function () { | ||
|
||
it('should create exception without details', function () { | ||
const response = { | ||
statusCode: 200, | ||
body: { | ||
message: 'test', | ||
code: 81022, | ||
more_info: 'https://www.twilio.com/docs/errors/81022', | ||
}, | ||
}; | ||
|
||
var exception = new RestException(response); | ||
expect(exception.status).toEqual(200); | ||
expect(exception.message).toEqual('test'); | ||
expect(exception.code).toEqual(81022); | ||
expect(exception.moreInfo).toEqual('https://www.twilio.com/docs/errors/81022'); | ||
expect(exception.details).toEqual(undefined); | ||
}); | ||
|
||
it('should create exception with details', function () { | ||
const details = { | ||
foo: 'bar', | ||
}; | ||
|
||
const response = { | ||
statusCode: 200, | ||
body: { | ||
message: 'test', | ||
code: 81022, | ||
more_info: 'https://www.twilio.com/docs/errors/81022', | ||
details: details, | ||
}, | ||
}; | ||
|
||
const exception = new RestException(response); | ||
expect(exception.details).toEqual(details); | ||
}); | ||
}); |