@jtorm/error-handler

1.0.3 • Public • Published

jTorm Error Handler

Install

npm install @jtorm/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": "noreply@test.com", "to": "info@test.com"}

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

Readme

Keywords

Package Sidebar

Install

npm i @jtorm/error-handler

Weekly Downloads

0

Version

1.0.3

License

MIT

Unpacked Size

6.54 kB

Total Files

9

Last publish

Collaborators

  • jtorm