【问题标题】:How do you set the response status code in Polka.js framework如何在 Polka.js 框架中设置响应状态码
【发布时间】:2021-04-28 19:06:11
【问题描述】:

看起来应该很简单。

尝试:

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

得到我:

TypeError: res.status 不是函数

这是在 sapper 中,不确定这是否会产生差异。

【问题讨论】:

    标签: javascript node.js sapper polka


    【解决方案1】:

    根据the docs,您使用res.statusCode = 500,或者如果您在中间件中抛出错误,您将使用err.code = 500

    【讨论】:

      【解决方案2】:

      这是如何完成的:

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

      【讨论】:

        猜你喜欢
        • 2020-04-20
        • 2021-07-21
        • 1970-01-01
        • 1970-01-01
        • 2015-04-20
        • 2016-11-21
        • 2011-09-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多