西纳特拉的全球救援和伐木例外
如何在出现异常时指定全局救援,如果您将 Sinatra 用于 API 或应用程序,您如何处理日志记录?
How do I specify a global rescue in case of an exception, and if you use Sinatra for an API or application, how do you handle logging?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
404 可以借助
not_found
方法来处理,例如:500 可以通过使用块调用 error 方法来处理,例如:
可以通过 sinatra 访问错误的详细信息
request.env
中的 .error 如下所示:404s can be handled with the help of the
not_found
method like eg:500s can be handled by calling the error method with a block, eg:
The details of the error can be accessed via the
sinatra.error
inrequest.env
like so:我很难在我的开发环境中开箱即用 - 为了让它工作,我必须在我的 sinatra 配置中将
show_exceptions
设置为 false。当此设置设置为 true 时,会启用在发生未处理异常时显示回溯和环境信息的错误页面,但我只能通过禁用它来触发自定义错误。
I had trouble getting this working out of the box in my dev environment - to get it to work, I had to set
show_exceptions
to false in my sinatra config.This setting, when set to true, enables error pages that show backtrace and environment information when an unhanded exception occurs, but I could only fire custom errors by disabling it.