在Google App Engine上使用Go语言,可以设置默认的错误页面吗?

huangapple go评论145阅读模式
英文:

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

&lt;error-page&gt;
		&lt;exception-type&gt;java.lang.Throwable&lt;/exception-type&gt;
		&lt;location&gt;/error&lt;/location&gt;
&lt;/error-page&gt;

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

huangapple
  • 本文由 发表于 2015年11月7日 23:09:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/33584254.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定