@jtorm/nodejs-error-handler
v1.0.2
Published
jTorm Error Handler
Downloads
221
Readme
jTorm Node.js Error Handler
Install
npm install @jtorm/nodejs-error-handler
Config
Add handlers to the error handler pool at the desired scope(s) defined in Winston RFC5424. The custom handler has to be a function. Next you can add the errorHandlerModel in your application in for example try/catch statements.
const myEmergErrorHandler = async (level, log) => {
// do something
};
const { errorHandlerModel, errorHandlerPoolModel } = require('@jtorm/error-handler');
errorHandlerPoolModel.emerg.push(myEmergErrorHandler);
(async () => {
try {
// do something
} catch (error) {
await errorHandlerModel.emerg(error);
}
})();
There is also a mail send action model available that accepts a .env
variable ERROR_HANDLER
with a from
and to
e-mail address:
ERROR_HANDLER={"from": "[email protected]", "to": "[email protected]"}
And you need to define the e-mail config with .env
variable EMAIL
that passes a config object to the nodemailer.createTransport
method: https://www.npmjs.com/package/nodemailer