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) {
            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",
                "wrapper": "data"
        }, function(err, response, body) {
            if (err) {
                return done(err);
   = { items: body };

    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
    It is quite a quick win so we likely make sure it is ready in the next release.

Log in to reply

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.