@blocklet/error
@blocklet/error provides utils for error handling.
Usage
Installation
npm install @blocklet/error
Examples
const { CustomError, formatError, getStatusFromError } = require('@blocklet/error');
// throw error
const err = new CustomError(400, 'test error');
throw err;
// get status from error
app.use((err, req, res, next) => {
const status = getStatusFromError(err);
res.status(status).json({ error: formatError(err) });
});