npm.io
0.3.5 • Published 9 months ago

@blocklet/error

Licence
ISC
Version
0.3.5
Deps
0
Size
9 kB
Vulns
0
Weekly
0

@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) });
});

Keywords