hapi-boombox
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -5,3 +5,3 @@ var Boom = require('boom'); | ||
var internals = { | ||
tags: ['hapi-boombox', 'warning'] | ||
tags: ['hapi-boombox'] | ||
}; | ||
@@ -11,2 +11,3 @@ | ||
internals.boom = function boom(error, returnError, convert) { | ||
var explosion = null; | ||
@@ -31,7 +32,7 @@ | ||
if (returnError) { | ||
var boom = Boom[data.type](); | ||
var customBoom = Boom[data.type](); | ||
explosion = new Error(data.message); | ||
Boom.wrap(explosion, boom.output.statusCode, data.message); | ||
Boom.wrap(explosion, customBoom.output.statusCode, data.message); | ||
} else { | ||
@@ -74,4 +75,16 @@ explosion = data.message; | ||
var explosion = internals.boom(error, returnError, convert); | ||
var log = { | ||
error: explosion.output || explosion, | ||
path: this.request.path, | ||
query: this.request.query, | ||
method: this.request.method | ||
}; | ||
server.log(internals.tags, explosion.output || explosion); | ||
if (this.request.auth.credentials) { | ||
log.credentials = { | ||
id: this.request.auth.credentials.id, | ||
name: this.request.auth.credentials.name | ||
}; | ||
} | ||
server.log(internals.tags, log); | ||
@@ -90,3 +103,3 @@ return this.response(explosion); | ||
server.log(['hapi-boombox'], 'Registered reply.boom() and server.boom()'); | ||
server.log(internals.tags, 'Registered reply.boom() and server.boom()'); | ||
@@ -93,0 +106,0 @@ return next(); |
{ | ||
"name": "hapi-boombox", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Boom error wrapper", | ||
@@ -28,2 +28,3 @@ "main": "index.js", | ||
"code": "1.x.x", | ||
"eslint-plugin-hapi": "1.x.x", | ||
"hapi": "8.3.x", | ||
@@ -30,0 +31,0 @@ "lab": "5.x.x" |
@@ -21,2 +21,14 @@ [![Build Status](https://travis-ci.org/AdriVanHoudt/Hapi-Boombox.svg)](https://travis-ci.org/AdriVanHoudt/Hapi-Boombox) | ||
If you try to convert a non existing key into a Boom error it will generate a `Internal Server Error` error. This is by design (atm) to make sure you notice it when you use an non implemented error key. | ||
###### Loging | ||
Both methods will do a `server.log` with `hapi-boombox` as tag and the result as data. | ||
`reply.boom` logs some aditional data: | ||
* error: the restult of Boombox, | ||
* path: the path from where Boombox was called, | ||
* query: the query params as object from the request, | ||
* method: the method from the request [get, post, ...], | ||
* credentials: if present this will be an object that includes 2 properties from `request.auth.credentials`. | ||
* `id` and `name`. | ||
* These are properties required by the author for his project. If you want more or something custumizable make an issue or PR. | ||
@@ -23,0 +35,0 @@ ## Test |
@@ -14,3 +14,3 @@ var Lab = require('lab'); | ||
it('Resgisters', function (done) { | ||
it('Registers', function (done) { | ||
@@ -24,5 +24,7 @@ var server = new Hapi.Server(); | ||
}, function (err) { | ||
expect(err).to.not.exist(); | ||
server.start(function(err) { | ||
expect(err).to.not.exist(); | ||
@@ -76,4 +78,5 @@ | ||
register: require('../'), | ||
options: { errors: errors} | ||
options: { errors: errors } | ||
}, function (err) { | ||
expect(err).to.not.exist(); | ||
@@ -94,4 +97,5 @@ | ||
register: require('../'), | ||
options: { errors: errors} | ||
options: { errors: errors } | ||
}, function (err) { | ||
expect(err).to.not.exist(); | ||
@@ -107,2 +111,8 @@ | ||
// set credentials for test | ||
request.auth.credentials = { | ||
id: 1, | ||
name: 'Box' | ||
}; | ||
return reply.boom(new Error('error')); | ||
@@ -136,4 +146,5 @@ } | ||
register: require('../'), | ||
options: { errors: errors} | ||
options: { errors: errors } | ||
}, function (err) { | ||
expect(err).to.not.exist(); | ||
@@ -179,2 +190,3 @@ | ||
}, function (err) { | ||
expect(err).to.not.exist(); | ||
@@ -193,3 +205,3 @@ | ||
lab.experiment('Main', function () { | ||
lab.experiment('Boom', function () { | ||
@@ -200,2 +212,3 @@ var server = new Hapi.Server(); | ||
lab.before(function (done) { | ||
server.connection(); | ||
@@ -207,2 +220,3 @@ | ||
}, function (err) { | ||
expect(err).to.not.exist(); | ||
@@ -209,0 +223,0 @@ |
Sorry, the diff of this file is not supported yet
17288
12
326
41
4