1.1.2 • Published 9 years ago
micro-json-error v1.1.2
micro-json-error
Wraps your micro service function to catch errors and display them as JSON.
Installation
npm install micro-json-error --saveUsage
const { createError } = require('micro');
const jsonError = require('micro-json-error');
module.exports = jsonError(async function (req, res) {
throw createError(400, 'Invalid data');
});API
jsonError(fn, { httpStatusCode = null, onError = null });httpStatusCode- Overrides thestatusCodefrom the error for the http response status code. Useful if you always want to return a 200, and show the originalstatusCodein the JSON body.onError- Callback function that will be passed theerror. Useful for logging.