如何访问 sinatra 错误处理程序中响应的 HTTP 代码?

发布于 2024-12-27 16:50:28 字数 346 浏览 1 评论 0原文

我在 sinatra 的早期版本(1.2.6)中使用了此代码,

error 400..510 do |app|
  do_something_with app.status
end

这里 app.status 是数字代码,即将在响应中使用的 400 到 510 之间的数字。

在最近的 (1.3.2) 版本中,这不再有效 - appnil。我查看了文档并尝试了 env['sinatra.error'] 但似乎也是 nil

这还有可能吗?

I used this code in an earlier(1.2.6) version of sinatra

error 400..510 do |app|
  do_something_with app.status
end

Here app.status is the numeric code, i.e. a number between 400 and 510 that will be used in the response.

With a recent (1.3.2) version, this no longer works - app is nil. I've looked at the documentation and tried env['sinatra.error'] but that appears to be nil as well.

Is this still possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

糖果控 2025-01-03 16:50:28

您尝试过response.status吗?您可能可以仅使用 status 来调用它,因为我相信它是一个助手。

Have you tried response.status? You can probably call it with just status as I believe it's a helper.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文