Skip to content

Instantly share code, notes, and snippets.

@heron2014
Created July 22, 2016 16:16
Show Gist options
  • Save heron2014/c547e99487cf300bda8dace621fe540b to your computer and use it in GitHub Desktop.
Save heron2014/c547e99487cf300bda8dace621fe540b to your computer and use it in GitHub Desktop.
hapi plugin to reformat boom errors to json-api
exports.register = function (plugin, options, done) {
plugin.ext('onPreResponse', function (request, reply) {
var response = request.response;
if (response.isBoom) {
var error = {
title: response.output.payload.error,
status: response.output.statusCode,
detail: response.output.payload.message
};
response.output.payload = { errors: [error] };
}
return reply.continue();
});
return done();
};
exports.register.attributes = {
name: 'hapi-boom-json-api',
version: '1.0.0'
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment