In the following code :
app.use('/Catalog', function(req, res)
{
let query = "select id, name from Category where id = ?";
let queryError = "select * from Category";
db.all(query, [req.query.id], (err, rows) => {
if(err == null){
res.writeHead(200, { 'Content-Type': 'text/plain'});
res.write(JSON.stringify(rows));
res.end();
}
else{
console.log(err);
db.all(queryError, (err, rows) => {
res.writeHead(200, { 'Content-Type': 'text/plain'});
res.write(JSON.stringify(rows));
res.end();
});
}
});
});
It seems that the else condition is not working.
Here are the rows of my Category table :
1|Motorcycles
2|Classic Cars
3|Trucks and Buses
4|Vintage Cars
5|Planes
6|Ships
7|Trains
The wanted behavior is that, if I ask for an id that is not in the table (/catalog?id=8 for example), the server should return all the categories available.
But here, instead of returning all the categories, it just returns
[]