I'm using Marklogic npm module v2.1.1 with my express(v4.16.4) Node app. In my controller function I'm using the db.eval method to return the data along with necessary status code using function xdmp.setResponseCode()
. Please find the below code snippet
// controller function
function getNewsArticleById(db: any, fileName: string, req: any, res: any, next: any) {
return db.eval(
`xdmp.setResponseCode(403, 'Forbidden');
{data: 'abc'};`,
{},
})
.result(
data => {
res.json(data[0].value);
},
err => {
console.log(err);
next(err);
});
}
The above function is attached to a route t return the desired response which could be either a success (200 response codes) or failures (400 response codes). The success case works fine but when ever the code sets to 400 or greater response code I get a 500 error saying
eval JavaScript on server: cannot process response with 403 status.
To me, it seems to be a limitation of the db.eval()
MarkLogic function
Can you please suggest me how to fix this? If not, what should be best alternative to handle it?