hapi-boom-jsend

2.0.0 • Public • Published

Build Status

hapi-boom-jsend

hapi plugin to convert boom errors into jsend responses

npm install hapi-boom-jsend

4XX responses

4XX responses created by boom are converted into jsend fail responses. The error and statusCode properties are left on the payload, while the others are coerced into jsend properties.

Before

{
  "statusCode": 401,
  "error": "Unauthorized",
  "message": "your message"
}

After

{
  "status": "fail",
  "error": "Unauthorized",
  "statusCode": 401,
  "data": { "message": "your message" }
}

5XX responses

5XX responses created by boom are converted into jsend error responses. The error, statusCode, and message properties are left on the payload. status and data are added as well.

Before

{
  "statusCode": 502,
  "error": "Bad Gateway",
  "message": "An internal server error occurred"
}

After

{
  "status": "error",
  "error": "Bad Gateway",
  "statusCode": 502,
  "data": {},
  "message": "An internal server error occurred"
}

Package Sidebar

Install

npm i hapi-boom-jsend

Weekly Downloads

1

Version

2.0.0

License

MIT

Last publish

Collaborators

  • bmharris