In the following code, I’m forcing an error. GOT error
is printed on console so the program is going in catch block, but express never sends a response with statusCode 500.
app.get("/", async (req, res) => {
try {
res.setHeader("Cache-control", `public, max-age=${maxAge}`);
await pipeline(got.stream(someUrl), res);
} catch (error) {
const errMsg =
error instanceof RequestError
? `GOT Request Error ${error.message}`
: "Some other Error " + (error as Error).message;
console.error(errMsg);
res.sendStatus(500);
}
});
Here is a screenshot from client
Environment:
- Nodejs v22.4.1
Expected result: express should send response with statusCode 500.
14