@vidaxl/exceptions

Package described vidaxl microservices exceptions

Usage no npm install needed!

<script type="module">
  import vidaxlExceptions from 'https://cdn.skypack.dev/@vidaxl/exceptions';
</script>

README

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.