0

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client at new NodeError (node:internal/errors:400:5) the error was occuirng again and again also tried try catch can anyone say how to solve it an its reasons?

            try {
                resultset[0].json = JSON.parse(resultset[0].json);
                return res.json({
                    success: true,
                    data: resultset,
                    code: 200
                });
            } catch (err) {
                console.log("Error parsing JSON string" + err);
                return res.json({
                    success: true,
                    msg: "json format was wrong",
                    code: 200
                });
         
        }
    }

i also tried this?

Deva
  • 3
  • 5

1 Answers1

4

How are you?

res.json() calls res.end() internally and you can't call another res.json() after the session ended.
It can't be said exactly without seeing the whole code but it seems that there is a code snippet that calls res.json() without return command above the code you provided here.

Hope this might help you.

starmori
  • 196
  • 5