Can the reponse stream be forced to error in case of jsreport error?



  • I pipe the response stream from jsreport directly to s3 for file storage. If jsreport is unavailable or other alike problem I will catch this in on('error', e =>.., because the stream will emitt an error.

    But if jsreport itself emits a problem it will do this inside the stream, i.e. the stream file is an error message instead of a pdf file.

    Is there any setting that makes jsreport close the stream instead?

    I suppose I could inspect the stream and try to identify error messages, but the message itself is mostly text based with no error codes.

    {"message":"Unable to find specified template or user doesnt have permissions to read it: rJxZpXJYwB_","stack":"Error: Unable to find specified template or user doesnt have permissions to read it: rJxZpXJYwB_\n    at module.exports (/app/node_modules/jsreport-core/lib/util/createError.js:11:13)\n    at Reporter.createError (/app/node_modules/jsreport-core/lib/reporter.js:288:12)\n    at AsyncFunction.<anonymous> (/app/node_modules/jsreport-templates/lib/templates.js:134:20)"}
    

    Real life scenario:
    If my API server requests a report from jsreport with wrong parameters (maybe an incorrect shortid), the user will get a report with an error message. If I could catch this I could handle the error a bit more user friendly.



  • I think you should primarily inspect the HTTP status code.



  • Thank you!
    I hadn't done my homework on streams. I naively thought that the error event on the stream would catch all problems. Didn't even know that I would get a response event as well as a readable stream from the request library.

    Reading the status code is of course the right way to do it.


Log in to reply
 

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