@vidaxl/exceptions
v1.0.9
Published
Package described vidaxl microservices exceptions
Downloads
342
Keywords
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 classException
.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 parametersstatus
andmessage
and creates new instance of concret HTTP exception.