是否可以在 Google App Engine 上使用 Go 设置默认错误页面

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页面,显示给用户。

当我的 Go Web 应用程序在 Google App Engine 上崩溃时,有没有办法做类似的事情?

是的,参见 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