Created
July 22, 2016 16:16
-
-
Save heron2014/c547e99487cf300bda8dace621fe540b to your computer and use it in GitHub Desktop.
hapi plugin to reformat boom errors to json-api
This file contains 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