README
About
Super-boom enhance the Hapi.js Boom package by allowing to add parameters in the body of the HTTP answer.
Installation
$ npm install super-boom --save
How to use
In your project file, include the package:
$ Boom = require('super-boom')({ origin: 'server1' }),
where the parameter are the optional default parameters (for now only origin is possible)
Boom.badRequest(httpCode, [message], [customCode], [parameters], [details])
In your code, you can now throw error like this:
$ Boom.customCode(403, 'This property already exist', "CUST_ERR_CODE", ['Some value', 'Blah'], { param1: 'blah', test: 2 }, 'server2');
The body of the HTTP answer should now look like this:
{"statusCode":403,"message":"This property already exist","code":"CUST_ERR_CODE","parameters":["Some value","Blah"], { param1: 'blah', test: 2 }, origin : 'server2' }
Where:
- httpCode: http code returned by the server
- message: a meaningful string that explain the problem to your users that only use your API
- customCode: your application code (which is different from http code) that refer to the exact problem. This code can be plugged in a frontend dictionary.
- parameters: array of strings to be plugged in the frontend dictionary with the customCode
- details: an object that can contain anything. Sometimes, you want your API to return additional details that can be used by the frontend.
- origin: the service or server who emitted the error