Custom Boom error messages

Viewed 9091

On my Hapi.js server, I'd like to send a specific message if an account does not have permission rights to access an api endpoint. The Boom message I have right now looks like this:

return reply(Boom.unauthorized("unauthorized access to this API."));

This returns a message that looks like this:

{
  "statusCode": 401,
  "error": "Unauthorized",
  "message": "unauthorized access to this API."
}

I would like to make it more customized to look like this:

{
  "success": false,
  "message": "unauthorized access to this API.",
  "csrf-decorator": "",
  "redirect": ""
}

Do we have access to customize the Boom error messages?

Thanks!

2 Answers
Related