1.0.9 • Published 3 years ago

@vidaxl/exceptions v1.0.9

Weekly downloads
20
License
ISC
Repository
-
Last release
3 years ago

Exceptions

Summary

This is an private npm module that provides a wrapper of Error type for use it with express framework for throwing server exceptions. And handlers for handle these exceptions.

Usage

  • Install package npm i -S @vidaxl/exceptions
  • Use it in your code for throw exceptions
  • Use handlers as last middleware in you app
const { 
    exceptionLogger,
    exceptionHandler,

} = require('@vidaxl/exceptions');

const app = express();

app.get('/example_1', async () => {
    throw new NotImplementedException('Method is not implemented.');
});

// NOTE: Should set up as last middleware
app.use(exceptionLogger);
app.use(exceptionHandler);

Exception API

  • constructor(message) - Create a instance of class Exception.
    • message type: String - A message which describes exception.
  • purifyStackTrace() - Exception instance method. Returns purified stack trace of exception.
  • toString() - Exception instance method. Returns a string represents exception data.
  • toJSON() - Exception instance method. Returns a json string with exception data.

HTTPException

Inherits Exception base class, and extend it with static method:

  • buildFromStatus(status, message) - receive parameters status and message and creates new instance of concret HTTP exception.
1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago