1.0.9 • Published 5 years ago
@vidaxl/exceptions v1.0.9
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.messagetype: String - A message which describes exception.
purifyStackTrace()-Exceptioninstance method. Returns purified stack trace of exception.toString()-Exceptioninstance method. Returns a string represents exception data.toJSON()-Exceptioninstance method. Returns a json string with exception data.
HTTPException
Inherits Exception base class, and extend it with static method:
buildFromStatus(status, message)- receive parametersstatusandmessageand creates new instance of concret HTTP exception.