1 | ;
|
2 |
|
3 | /**
|
4 | * Monitors a Promise and returns success or error based on promise outcome.
|
5 | *
|
6 | * @param {Response} res use as res.resolve(...)
|
7 | * @param {Promise} promiseObj Promise objecy to monitor
|
8 | * @param {string|object} [message=undefined] success or error message to return; if this is not specified, result of promise is returned.
|
9 | * @param {string} [audit=false] audit event type. note that '_SUCCESS' or '_FAILURE' is attached to this type depenidng on outcome
|
10 | * @param {string} [extra=undefined] extra audit payload which may help debug event
|
11 | */
|
12 | function resolve(res, promiseObj, message = undefined, audit = false, extra = undefined)
|
13 | {
|
14 | promiseObj.then((response) =>
|
15 | {
|
16 | res.success(message || response, audit && `${audit}_SUCCESS`, extra);
|
17 | }, res.reject(audit && `${audit}_FAILURE`, extra));
|
18 | }
|
19 |
|
20 | module.exports = resolve;
|