Skip to content

Commit

Permalink
Merge 2b3a740 into 9eb0cb0
Browse files Browse the repository at this point in the history
  • Loading branch information
orthagonal committed Nov 18, 2017
2 parents 9eb0cb0 + 2b3a740 commit 91bb24d
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 200 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
language: node_js

node_js:
- 4
- 5
- 6
- 8

script: npm run test-travis
39 changes: 22 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
'use strict';

exports.register = function(server, options, next) {
server.ext('onPreResponse', (request, reply) => {
const register = async function(server, options) {
server.ext('onPreResponse', async (request, h) => {
const response = request.response;
const path = request.path;

if (response.isBoom) {
//if application/json, skip
if (request.headers.accept && request.headers.accept.match(/application\/json/)) {
return reply.continue();
return h.continue;
}
if (options.errorBlacklist && path.match(new RegExp(options.errorBlacklist))) {
return reply.continue();
return h.continue;
}
if (options.logErrors && response.output.statusCode === 500) {
server.log(['error'], {
Expand All @@ -25,16 +24,17 @@ exports.register = function(server, options, next) {
if (options.url) {
if (request.path === options.url) {
//error page is erroring
return reply(`${request.query.statusCode} - ${request.query.error}`);
return `${request.query.statusCode} - ${request.query.error}`;
}
const { statusCode, error, message } = response.output.payload
server.inject({
const res = await server.inject({
url: `${options.url}?statusCode=${statusCode}&error=${error}&message=${message}`,
method: 'GET',
}, (res) => {
reply(null, res.payload).code(response.output.statusCode);
})
return;
});

return h
.response(res.payload)
.code(response.output.statusCode);
}

const payload = response.output.payload;
Expand All @@ -55,15 +55,20 @@ exports.register = function(server, options, next) {
}
// a default error message:
if (!options.view) {
return reply(`<h1>There was an error</h1><h2>${context.error}: ${context.message}</h2>`).code(response.output.statusCode);
return h
.response(`<h1>There was an error</h1><h2>${context.error}: ${context.message}</h2>`)
.code(response.output.statusCode);
}
return reply.view(options.view, context).code(response.output.statusCode);
return h
.view(options.view, context)
.code(response.output.statusCode);
}
reply.continue();
return h.continue;
});
next();
};

exports.register.attributes = {
pkg: require('./package.json')
exports.plugin = {
once: true,
pkg: require('./package.json'),
register
};
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
},
"devDependencies": {
"boom": "^4.2.0",
"code": "^4.0.0",
"code": "^5.1.2",
"coveralls": "^2.11.8",
"eslint": "^3.9.1",
"eslint-config-firstandthird": "^3.0.2",
"eslint-plugin-import": "^2.2.0",
"handlebars": "^4.0.5",
"hapi": "^16.0.2",
"lab": "^11.1.0",
"vision": "^4.1.0"
"hapi": "^17.0.1",
"lab": "^15.1.2",
"vision": "^5.2.0"
}
}
Loading

0 comments on commit 91bb24d

Please sign in to comment.