8.0.2 • Published 2 years ago

nestjs-exceptions v8.0.2

Weekly downloads
89
License
MIT
Repository
github
Last release
2 years ago

Nest.js exceptions

npm.io

Provides Nest.js custom exceptions and exception filters.

Installation

$ npm i nestjs-exceptions

Usage

Nest.js compatibility matrix

Nest.js versionnestjs-exceptions compatible version
8.x.x8.x.x
7.x.x7.x.x

Integration Error

You might want to use IntegrationError to wrap integration errors with a custom message.

throw new IntegrationError(`Service runtime error.`, causeError);

Bootstrap with global exception filter

const bootstrap = async () => {
    const app = await NestFactory.create(AppModule);
    app.useGlobalFilters(new GlobalExceptionFilter());
    ...
    await app.listen(3000);
};
bootstrap();

GlobalExceptionFilter takes care mainly of internal server errors. You can configure it during instantiation so that the original cause of 500 errors are returned back to the client. The default is false for security reasons.

const sendInternalServerErrorCause = true;
new GlobalExceptionFilter(sendInternalServerErrorCause);

GlobalExceptionFilter logging setup

By default, only 500 errors are logged in the server side. This can avoid performance issues or Denial of Service attacks because the server is being to much verbose logging.

Anyways, for development reasons or debugging it's possible to log all errors:

const sendInternalServerErrorCause = false;
const logAllErrors = true;
new GlobalExceptionFilter(sendInternalServerErrorCause, logAllErrors);

Or log only specific errors (besides 500):

const sendInternalServerErrorCause = false;
const logAllErrors = false;
const logErrorsWithStatusCode = [400, 401];
new GlobalExceptionFilter(sendInternalServerErrorCause, logAllErrors, logErrorsWithStatusCode);
8.0.2

2 years ago

8.0.1

2 years ago

8.0.0

2 years ago

7.6.7

3 years ago

7.6.6

3 years ago

7.6.5

3 years ago

7.6.4

3 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago