Skip to content

Commit

Permalink
Adding error handlers to managed vms hello world samples. (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Wayne Parrott committed Jun 7, 2016
1 parent 8ed683d commit 44d58cd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions appengine/flexible/hello_world/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.

# [START app]
import logging

from flask import Flask


Expand All @@ -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: <pre>{}</pre>
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.
Expand Down
11 changes: 11 additions & 0 deletions appengine/flexible/hello_world_compat/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.

# [START app]
import logging

from flask import Flask


Expand All @@ -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: <pre>{}</pre>
See logs for full stacktrace.
""".format(e), 500
# [END app]

0 comments on commit 44d58cd

Please sign in to comment.