英文:
Is it possible to set a default error page using Go on Google App Engine
问题
我之前使用过J2EE,在web.xml
中可以添加以下配置:
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/error</location>
</error-page>
以上代码的效果是,如果发生未处理的异常,它将被传递到/error
页面,并显示给用户。
在Google App Engine上,当我的Go Web应用程序发生panic时,是否有类似的方法可以实现这个功能?
英文:
I've previously worked with J2EE where it's possible to add this configuration to web.xml
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/error</location>
</error-page>
The effect of the above code is that if an unhanded exception is thrown, it will be passed to the /error
page, which will be shown to the user.
Is there a way to do something similar to this when my Go web application panics on Google App Engine?
答案1
得分: 1
是的,请参考自定义错误响应:
> 当发生某些错误时,App Engine会提供一个通用的错误页面。您可以配置您的应用程序,以提供一个自定义的静态文件,而不是这些通用的错误页面,只要自定义错误数据小于10千字节。您可以通过在应用程序的app.yaml文件中指定文件来设置为每个支持的错误代码提供不同的静态文件。要提供自定义错误页面,请在您的app.yaml中添加一个error_handlers部分,如下所示:
> error_handlers:
> - file: default_error.html
>
> - error_code: over_quota
> file: over_quota.html
英文:
Yes, see Custom error responses:
> When certain errors occur, App Engine serves a generic error page. You
> can configure your app to serve a custom static file instead of these
> generic error pages, so long as the custom error data is less than 10
> kilobytes. You can set up different static files to be served for each
> supported error code by specifying the files in your app's app.yaml
> file. To serve custom error pages, add a error_handlers section to
> your app.yaml, as in this example:
>
> error_handlers:
> - file: default_error.html
>
> - error_code: over_quota
> file: over_quota.html
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论