boom-express
Version:
29 lines (20 loc) • 814 B
text/typescript
var boom = require('boom');
export class BoomExpress {
Boom(outputTransformer) {
return function (req, res, next) {
if (res.boom) throw new Error('boom already exists on response object');
res.boom = {};
Object.keys(boom).forEach(function (key) {
if (typeof boom[key] !== 'function') return;
res.boom[key] = function () {
var boomed = boom[key].apply(this, arguments);
if (typeof outputTransformer === 'function') {
boomed = outputTransformer(boomed);
}
res.status(boomed.output.statusCode).send(boomed.output.payload);
};
});
next();
};
}
}