diff --git a/appengine/flexible/hello_world/main.py b/appengine/flexible/hello_world/main.py index 7115570b5681..ae08dcdfa6e6 100644 --- a/appengine/flexible/hello_world/main.py +++ b/appengine/flexible/hello_world/main.py @@ -13,6 +13,8 @@ # limitations under the License. # [START app] +import logging + from flask import Flask @@ -25,6 +27,14 @@ def hello(): return 'Hello World!' +@app.errorhandler(500) +def server_error(e): + logging.exception('An error occurred during a request.') + return """ + An internal error occurred:
{}
+ See logs for full stacktrace. + """.format(e), 500 + if __name__ == '__main__': # This is used when running locally. Gunicorn is used to run the # application on Google App Engine. See entrypoint in app.yaml. diff --git a/appengine/flexible/hello_world_compat/main.py b/appengine/flexible/hello_world_compat/main.py index 28e73368add0..9150b7229e48 100644 --- a/appengine/flexible/hello_world_compat/main.py +++ b/appengine/flexible/hello_world_compat/main.py @@ -13,6 +13,8 @@ # limitations under the License. # [START app] +import logging + from flask import Flask @@ -23,4 +25,13 @@ def hello(): """Return a friendly HTTP greeting.""" return 'Hello World!' + + +@app.errorhandler(500) +def server_error(e): + logging.exception('An error occurred during a request.') + return """ + An internal error occurred:
{}
+ See logs for full stacktrace. + """.format(e), 500 # [END app]