UNPKG

lugger

Version:

Lugger is an automation framework running on customizable Typescript DSL

38 lines 1.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HttpFinalizerExpress = void 0; const serializationError = JSON.stringify({ status: 'error', code: 500, message: 'Server was unable to serialize the 200 response', }); function HttpFinalizerExpress(req, res) { return { onThrow: async (e) => { if (res.writableEnded) { return; } const code = e.code ? e.code : 500; res.status(code).end(JSON.stringify({ status: 'error', code, message: e.message, })); }, onReturn: async (r) => { if (res.writableEnded) { return; } if (typeof r === 'string') { res.status(200).end(r); } else { try { r = JSON.stringify(r); res.status(200).end(r); } catch (e) { res.status(500).end(serializationError); } } }, }; } exports.HttpFinalizerExpress = HttpFinalizerExpress; //# sourceMappingURL=http.model.js.map