0

So basically, I am doing this:

app.get("/moderation_enabled", (req, res) => {
    var id = req.param("id");

    con.query(`SELECT moderation FROM server_settings WHERE id=${id}`, (err, result) => {
        if (err) { 
          return res.send(`error ${err}`);
        }
        if (result[0].moderation == undefined){
          return res.send("server not found");
        } else{
          return res.send(result[0].moderation);
        }
    });
})

but, when I run it, when I get an invalid id, then it says server not found, but when it does find it, it gives this error:

Here is my error:

thanks in advance!

peteb
  • 18,552
  • 9
  • 50
  • 62
Robert Westbury
  • 64
  • 1
  • 3
  • 10
  • Possible duplicate of [RangeError: Invalid status code: 0](https://stackoverflow.com/questions/38061781/rangeerror-invalid-status-code-0) – Raghu Dec 02 '17 at 08:48

1 Answers1

0

Because the value of result[0].moderation is just a Number 0, and res.send() sees it as a status code, then you get the error. Convert result[0].moderation to a string can solve your problem.

 return res.send(`${result[0].moderation}`);
ufxmeng
  • 2,570
  • 1
  • 13
  • 14