Last active
August 29, 2015 14:26
-
-
Save mmadden/a8b1888e14d20bf8ff22 to your computer and use it in GitHub Desktop.
hapi plugin to reformat boom errors to json-api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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