How to send 204 instead of empty report
-
Hi,
We have a report, which fetches data from a REST webservice with beforeRender. Sometimes this data is empty - resulting in an empty report (a complete white pdf).
Is it possible to exit report generation in beforeRender (if REST response is empty) and send a 204 status to the calling client?
Here some code:
function beforeRender(req, res, done) { require('request')({ rejectUnauthorized: false, //Fehlerbehebung: UNABLE_TO_VERIFY_LEAF_SIGNATURE url: 'https://someurl/api/v2/something', json: true, encoding: 'utf8', method: 'POST', headers: { 'Authorization': 'Basic abc123', 'X-DreamFactory-Api-Key': 'abc123', 'Accept': 'application/json' }, body: { "params": [{ "name": "loginin", "param_type": "IN", "value": req.data.loginin }], "wrapper": "data" } }, function(err, response, body) { if (err) { return done(err); } req.data = { items: body }; done(); }); }
Reto E.
-
Thank you for your request.
I am afraid it isn't possible to set custom status code from script at this moment.
I've submitted this feature request to the github
https://github.com/jsreport/jsreport/issues/653
It is quite a quick win so we likely make sure it is ready in the next release.