1.1.1 • Published 1 year ago

@vavra7/errors v1.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

Errors

Errors handling for Express application containing a set of predefined errors.

Preconditions

Express application

Installation

npm install @vavra7/errors

Set up

Apply errorHandlerMiddleware as very last middleware in Express app.

import express from 'express';
import { errorHandlerMiddleware } from '@vavra7/errors';

const app = express();

app.use(errorHandlerMiddleware);

Usage

  • In controllers catch and pass all errors in Express next() function.
  • You can use predefined errors that can be exported from package.

Example

import express from 'express';
import { errorHandlerMiddleware, NotAuthenticatedError } from '@vavra7/errors';

const app = express();

app.get('/posts/:id', (req, res, next) => {
  try {
    if (!req.context?.user) {
      throw new NotAuthenticatedError();
    }
    res.send('some post')
  } catch (err) {
    next(err)
  }
})

app.use(errorHandlerMiddleware);
1.1.1

1 year ago

1.0.2

1 year ago

1.1.0

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago