I’m trying to fire a 404 from a list. Something like this:
function (head, req) {
var row;
var returnArr = [];
while (row = getRow()) {
returnArr.push(row.value);
}
if(returnArr.length === 0) {
start({code:404});
send(JSON.stringify({error:"not found"}));
} else {
send(JSON.stringify(returnArr));
}
};
I found some help here. However, is seams that I’m calling the start() function to late. When the start() function is right at the beginning (in the first line) it works.
Of course I can not call start() earlier, since I first have to determine if the view has any rows.
How to implement this?
UPDATE:
It indeed seams that start() does not work after getRow() is called. Not sure if this is an expected behavior. Also this doesn’t work either:
function (head, req) {
var row;
var returnArr = [];
while (row = getRow()) {
returnArr.push(row.value);
}
if(returnArr.length === 0) {
throw (['error', 'not_found', 'Some message like Page not found']);
} else {
send(JSON.stringify(returnArr));
}
};
Yes, this is an open bug. Unfortunately Jira is down so I can’t link to the issue. But it is as you found, you cant currently call getRow() before start().