roccomuso / node-webhooks

:arrow_right_hook: Node.js module to create and trigger your own webHooks.
190 stars 47 forks source link

Exposed emitter for getting events information #5

Closed alopezvillaverde closed 7 years ago

alopezvillaverde commented 7 years ago

Using new event emitter library for exposing request information on webHook trigger.

var webHooks = new WebHooks({
    db: WEBHOOKS_DB,
    DEBUG: true
});

var emitter = webHooks.getEmitter();

emitter.on('*.success', function (shortname, statusCode, body) {
    log.info('Success on trigger webHook' + shortname + 'with status code', statusCode, 'and body', body);
});

emitter.on('*.failure', function (shortname, statusCode, body) {
    log.error('Error on trigger webHook' + shortname + 'with status code', statusCode, 'and body', body);
});

This makes possible checking if a webHook trigger was succesful or not getting request information such as status code or response body.

The format for the events is builded as eventName.result. The choosen library eventemitter2 provides a lot of freedom for listening events. For example: