diff --git a/README.md b/README.md index cf30994..7c7b847 100644 --- a/README.md +++ b/README.md @@ -18,3 +18,4 @@ Usage }).then(function(response) { console.log(response); }); + diff --git a/requestError.js b/requestError.js index e252e3c..10dc9bf 100644 --- a/requestError.js +++ b/requestError.js @@ -1,17 +1,14 @@ 'use strict'; -var _ = require('lodash'); - var SuiteRequestError = function(message, code, data) { this.message = message; this.name = 'SuiteRequestError'; this.code = code; - this.data = { - replyText: message - }; - this.stack = new Error().stack; - - _.extend(this, data); + this.data = data || {}; + if (!this.data.replyText) { + this.data.replyText = message; + } + this.stack = new Error(message).stack; }; SuiteRequestError.prototype = Object.create(Error.prototype); diff --git a/requestError.spec.js b/requestError.spec.js new file mode 100644 index 0000000..5e451c7 --- /dev/null +++ b/requestError.spec.js @@ -0,0 +1,25 @@ +'use strict'; + +var SuiteRequestError = require('./requestError'); + +describe('SuiteRequestError', function() { + it('should extend base Error class', function() { + var error = new SuiteRequestError(); + + expect(error).to.be.an.instanceOf(Error); + }); + + it('should store constructor parameters', function() { + var error = new SuiteRequestError('Invalid request', 400, { detailedMessage: 'Line too long' }); + + expect(error.message).to.eql('Invalid request'); + expect(error.code).to.eql(400); + expect(error.data).to.eql({ detailedMessage: 'Line too long', replyText: 'Invalid request' }); + }); + + it('should always contain replyText in data', function() { + var error = new SuiteRequestError('Unauthorized'); + + expect(error.data.replyText).to.eql('Unauthorized'); + }); +});