Friso
Friso

Reputation: 2428

How to return an express response when catching an error?

I catch and handle the error like so:

catch (err) {
    console.log(err);

    res.statusCode = 400;
    res.statusMessage = err;
}

The log works, however I don't receive a response in my browser and the call is "pending".

For the full code see: https://github.com/FrisoDenijs/WH40K-ArmyList/blob/3022f4a50b47eaecd2f5e68d6b67a16792217f1f/server/src/app/routes/detachments.route.js#L15

Upvotes: 0

Views: 33

Answers (1)

Guy who types fast
Guy who types fast

Reputation: 559

res.statusMessage is not sending the response, use res.send(err); instead

Upvotes: 2

Related Questions