如何确保 Rails 优雅死亡?
我对 ruby 和 Rails 很陌生,但似乎比我预期的更好地掌握了它的窍门......
所以我有一些实例方法,在其中调用 ruby gems。当其中一个抛出错误时,我如何才能将其优雅地传递回客户端?如果可以的话,要么让它继续运行并显示一条错误消息,要么死掉并给出一条错误消息。
仍然让我的头脑陷入困境。我知道我应该进行测试,这就是我要做的下一件事......这就是测试的目的吗?我的意思是,我将模拟各种情况并查看代码如何反应,然后尝试让它优雅地执行此操作......但是,我可以使用一些关于如何操作的指导。
例如,如果我在一个页面上有 4 个部分,每个部分都是来自远程站点的提要,我会喜欢它。如果一个网站出现故障,我希望只是该部分出现故障,其余部分正常运行。
所以,我有点不确定如何实现这一点。或者,这是一件非常DIY的事情吗?
I am new to ruby and rails but seem to be getting the hang of it better than I expected...
So I have a few instance methods, within which calls to ruby gems are made. When one of them throws an error, how do I get that to gracefully pass back to the client? Either let it keep going if it can and display an error message, or die and give one.
Still getting my head wrapped around things. I know I should be testing and thats the next thing i'm doing... is thats what testings for? I mean, i'm going to be simulating various situations and seeing how the code reacts and then trying to get it to do so gracefully... but, i could use some guidance as to how.
I'd like it if, for example, I have 4 partials on a page, each a feed from a remote site. if a website goes down, i'd want just that partial to go down, and the rest to function.
So, i am a little unsure of how to accomplish this. or, is this a very DIY thing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要包装可能在开始-救援-结束中引发错误的代码。看看:http://ruby-doc.org/docs/ProgrammingRuby/ html/tut_exceptions.html
基本上,告诉 ruby 如何“拯救”这些错误。
You need to wrap code that could throw an error in a begin-rescue-end. Check it out: http://ruby-doc.org/docs/ProgrammingRuby/html/tut_exceptions.html
Basically, tell ruby how to "rescue" those errors.