如何访问 sinatra 错误处理程序中响应的 HTTP 代码?
我在 sinatra 的早期版本(1.2.6)中使用了此代码,
error 400..510 do |app|
do_something_with app.status
end
这里 app.status
是数字代码,即将在响应中使用的 400 到 510 之间的数字。
在最近的 (1.3.2) 版本中,这不再有效 - app
为 nil
。我查看了文档并尝试了 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您尝试过response.status吗?您可能可以仅使用
status
来调用它,因为我相信它是一个助手。Have you tried
response.status
? You can probably call it with juststatus
as I believe it's a helper.