首页 > 解决方案 > 从 Google Cloud Endpoints 后面的 appengine 返回自定义错误

问题描述

我使用 flask 和 python 3.6 作为后端服务,部署到 GCP 中的 App Engine。此后端位于 Cloud Run 中部署的 Google Cloud Endpoints 后面。Endpoints 接收我所有的 404 消息,然后只返回 404 Not Found。我想使用 404 代码发送更多信息性错误消息。有没有办法使用我当前的设置来做到这一点?谢谢

标签: google-cloud-endpoints

解决方案


您可以创建自定义 404 html 页面:

@app.errorhandler(404)
def page_not_found(e):
    return render_template('404.html'), 404

然后,您需要创建 404.html 文件。


推荐阅读