Comparing version 1.2.0 to 1.3.0
26
index.js
@@ -72,2 +72,28 @@ 'use strict'; | ||
/** | ||
* Wraps an error as a boom error and logs it. | ||
* @param {Error} err Error to wrap. | ||
* @param {Number} code HTTP Response code for the boom error. | ||
* @param {String} message Additional message for the error. | ||
* @return {Error} The boom error that wraps the given error. | ||
*/ | ||
ErrorCat.prototype.wrap = function (err, code, message) { | ||
var boomError = Boom.wrap(err, code, message); | ||
this.log(boomError); | ||
return boomError; | ||
}; | ||
/** | ||
* Wraps an error as a boom error and reports it via rollbar. | ||
* @param {Error} err Error to wrap. | ||
* @param {Number} code HTTP Response code for the boom error. | ||
* @param {String} message Additional message for the error. | ||
* @return {Error} The boom error that wraps the given error. | ||
*/ | ||
ErrorCat.prototype.wrapAndReport = function (err, code, message) { | ||
var boomError = this.wrap(err, code, message); | ||
this.report(boomError); | ||
return boomError; | ||
}; | ||
/** | ||
* Responder that sends error information along with a 500 status code. | ||
@@ -74,0 +100,0 @@ * @param {Error} err Error to use for the response. |
{ | ||
"name": "error-cat", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "A friendly feline companion that helps you create, track, and report errors.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -203,2 +203,84 @@ 'use strict'; | ||
describe('wrap', function() { | ||
var error = new ErrorCat(); | ||
beforeEach(function (done) { | ||
sinon.stub(error, 'log'); | ||
sinon.stub(error, 'report'); | ||
sinon.spy(Boom, 'wrap'); | ||
done(); | ||
}); | ||
afterEach(function (done) { | ||
error.log.restore(); | ||
error.report.restore(); | ||
Boom.wrap.restore(); | ||
done(); | ||
}); | ||
it('should wrap the given error as a boom error', function(done) { | ||
var err = new Error('Wowza'); | ||
var result = error.wrap(err, 502, 'hello world'); | ||
expect(result.isBoom).to.be.true(); | ||
expect(Boom.wrap.calledOnce).to.be.true(); | ||
expect(Boom.wrap.calledWith(err, 502, 'hello world')).to.be.true(); | ||
done(); | ||
}); | ||
it('should log the error', function(done) { | ||
var err = new Error('sup'); | ||
var result = error.wrap(err, 404, 'not foundxorz'); | ||
expect(error.log.calledOnce).to.be.true(); | ||
expect(error.log.calledWith(result)).to.be.true(); | ||
done(); | ||
}); | ||
it('should not report the error', function(done) { | ||
error.wrap(new Error('playa'), 400, 'user errrrr'); | ||
expect(error.report.notCalled).to.be.true(); | ||
done(); | ||
}); | ||
}); // end 'wrap' | ||
describe('wrapAndReport', function() { | ||
var error = new ErrorCat(); | ||
beforeEach(function (done) { | ||
sinon.stub(error, 'log'); | ||
sinon.stub(error, 'report'); | ||
sinon.spy(Boom, 'wrap'); | ||
done(); | ||
}); | ||
afterEach(function (done) { | ||
error.log.restore(); | ||
error.report.restore(); | ||
Boom.wrap.restore(); | ||
done(); | ||
}); | ||
it('should wrap the given error as a boom error', function(done) { | ||
var err = new Error('Hello'); | ||
var result = error.wrapAndReport(err, 500, 'supa'); | ||
expect(result.isBoom).to.be.true(); | ||
expect(Boom.wrap.calledOnce).to.be.true(); | ||
expect(Boom.wrap.calledWith(err, 500, 'supa')).to.be.true(); | ||
done(); | ||
}); | ||
it('should log the error', function(done) { | ||
var result = error.wrapAndReport(new Error('zzz'), 409, 'wowowo'); | ||
expect(error.log.calledOnce).to.be.true(); | ||
expect(error.log.calledWith(result)).to.be.true(); | ||
done(); | ||
}); | ||
it('should report the error', function(done) { | ||
var result = error.wrapAndReport(new Error('29292'), 599, 'yuss'); | ||
expect(error.report.calledOnce).to.be.true(); | ||
expect(error.report.calledWith(result)).to.be.true(); | ||
done(); | ||
}); | ||
}); // end 'wrapAndReport' | ||
describe('respond', function() { | ||
@@ -205,0 +287,0 @@ var error = new ErrorCat(); |
21904
497