micro-json-error
Wraps your micro service function to catch errors and display them as JSON.
Installation
npm install micro-json-error --save
Usage
const createError = ;const jsonError = ; moduleexports = ;
API
jsonError(fn, { httpStatusCode = null, onError = null });
httpStatusCode
- Overrides thestatusCode
from the error for the http response status code. Useful if you always want to return a 200, and show the originalstatusCode
in the JSON body.onError
- Callback function that will be passed theerror
. Useful for logging.