如何设置全局 DeadlineExceededError 处理程序?
我想捕获并处理 DeadlineExceededError,以便用户不会看到 App Engine 默认抛出的标准“服务器错误”页面。
我知道在您的请求中覆盖handle_exception时不会捕获 DeadlineExceededErrors处理程序(我们已经这样做了)。
我尝试过使用自定义 error_handlers 应用,但到目前为止尚未成功。 yaml 配置 像这样:
error_handlers:
- error_code: timeout
file: timeout.html
...但这似乎也没有捕获 DeadlineExceededErrors,除非我做错了什么。
我知道我可以使用以下模式来捕获特定请求处理程序中的 DeadlineExceededErrors:
class MainPage(webapp.RequestHandler):
def get(self):
try:
# Do stuff...
except DeadlineExceededError:
# Many Whelps! Handle it!
...但我想避免将其添加到我的应用程序中的每个请求处理程序中。
我怎样才能在全球范围内抓住这些难以捉摸的傻瓜?
I'd like to catch and handle DeadlineExceededError so users don't see the standard "Server Error" page that App Engine throws by default.
I know that DeadlineExceededErrors are not caught when overriding handle_exception in your request handler (we already do this).
I have tried, unsuccessfully so far, to use the custom error_handlers app.yaml configuration like so:
error_handlers:
- error_code: timeout
file: timeout.html
...but that also doesn't seem to catch DeadlineExceededErrors, unless I'm doing something wrong.
I am aware that I can use the following pattern to catch DeadlineExceededErrors inside particular request handlers:
class MainPage(webapp.RequestHandler):
def get(self):
try:
# Do stuff...
except DeadlineExceededError:
# Many Whelps! Handle it!
...but I would like to avoid adding this to every single request handler in my application.
How can I globally catch these elusive suckers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种可能的解决方案是使用 webapp2,它本身就是一个非常简洁的框架,并且比原始 webapp 有很多有用的东西。使用webapp2,可以在handle_500方法中处理异常,如下:
One possible solution is to use webapp2, which is a pretty neat framework as it is and has a lot of useful stuff over the original webapp. With webapp2, you can handle the exception in the handle_500 method, as follows: