How do you set the response status code in Polka.js framework

295 Views Asked by At

Seems like it should be simple.

Trying:

res.status(500).send({ error: "That type already exists." })

Gets me:

TypeError: res.status is not a function

This is in sapper, not sure if that makes a diff.

2

There are 2 best solutions below

0
Zac Anger On

According to the docs, you use res.statusCode = 500, or if you're throwing an error in a middleware, you'd use err.code = 500.

0
mtyson On

Here's how it's done:

res.writeHead(500, {'Content-Type': 'text/plain'})