diff --git a/managed_vms/analytics/main.py b/managed_vms/analytics/main.py index 496497057623..b12c8cc54885 100644 --- a/managed_vms/analytics/main.py +++ b/managed_vms/analytics/main.py @@ -13,6 +13,7 @@ # limitations under the License. # [START app] +import logging import os from flask import Flask @@ -57,6 +58,15 @@ def track_example(): return 'Event tracked.' +@app.errorhandler(500) +def server_error(e): + logging.exception('An error ocurred 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/managed_vms/cloudsql/main.py b/managed_vms/cloudsql/main.py index baff9df43f9e..f3ba7a41d614 100644 --- a/managed_vms/cloudsql/main.py +++ b/managed_vms/cloudsql/main.py @@ -13,6 +13,7 @@ # limitations under the License. import datetime +import logging import os import socket @@ -80,6 +81,15 @@ def index(): # [END example] +@app.errorhandler(500) +def server_error(e): + logging.exception('An error ocurred 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/managed_vms/datastore/main.py b/managed_vms/datastore/main.py index c924ae6d4533..9c5b06b5c133 100644 --- a/managed_vms/datastore/main.py +++ b/managed_vms/datastore/main.py @@ -13,6 +13,7 @@ # limitations under the License. import datetime +import logging import os import socket @@ -65,6 +66,15 @@ def index(): # [END example] +@app.errorhandler(500) +def server_error(e): + logging.exception('An error ocurred 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/managed_vms/disk/main.py b/managed_vms/disk/main.py index ee5c9ed5018e..f4ec27fb611f 100644 --- a/managed_vms/disk/main.py +++ b/managed_vms/disk/main.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import logging import os import socket @@ -58,6 +59,15 @@ def index(): # [END example] +@app.errorhandler(500) +def server_error(e): + logging.exception('An error ocurred 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/managed_vms/extending_runtime/main.py b/managed_vms/extending_runtime/main.py index 1c75a7bbff20..d302052ce6b1 100644 --- a/managed_vms/extending_runtime/main.py +++ b/managed_vms/extending_runtime/main.py @@ -13,6 +13,7 @@ # limitations under the License. # [START app] +import logging import subprocess from flask import Flask @@ -29,6 +30,15 @@ def fortune(): # [END example] +@app.errorhandler(500) +def server_error(e): + logging.exception('An error ocurred 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 CMD in Dockerfile. diff --git a/managed_vms/extending_runtime_compat/main.py b/managed_vms/extending_runtime_compat/main.py index e9bc3eacfa1a..5fd2c3718f5d 100644 --- a/managed_vms/extending_runtime_compat/main.py +++ b/managed_vms/extending_runtime_compat/main.py @@ -13,6 +13,7 @@ # limitations under the License. # [START app] +import logging import subprocess from flask import Flask @@ -27,4 +28,14 @@ def fortune(): output = subprocess.check_output('/usr/games/fortune') return output, 200, {'Content-Type': 'text/plain; charset=utf-8'} # [END example] + + +@app.errorhandler(500) +def server_error(e): + logging.exception('An error ocurred during a request.') + return """ + An internal error occurred:
{}
+ See logs for full stacktrace. + """.format(e), 500 + # [END app] diff --git a/managed_vms/mailgun/main.py b/managed_vms/mailgun/main.py index 0ba388bccea0..140c24c93043 100644 --- a/managed_vms/mailgun/main.py +++ b/managed_vms/mailgun/main.py @@ -13,6 +13,7 @@ # limitations under the License. # [START app] +import logging import os from flask import Flask, render_template, request @@ -78,6 +79,15 @@ def send_email(): return 'Email sent.' +@app.errorhandler(500) +def server_error(e): + logging.exception('An error ocurred 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/managed_vms/memcache/main.py b/managed_vms/memcache/main.py index 3cda68026a0e..77b790a4f5cb 100644 --- a/managed_vms/memcache/main.py +++ b/managed_vms/memcache/main.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import logging import os from flask import Flask @@ -42,6 +43,15 @@ def index(): # [END example] +@app.errorhandler(500) +def server_error(e): + logging.exception('An error ocurred 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/managed_vms/pubsub/main.py b/managed_vms/pubsub/main.py index f9b3893fb4a3..f813b823c172 100644 --- a/managed_vms/pubsub/main.py +++ b/managed_vms/pubsub/main.py @@ -15,6 +15,7 @@ # [START app] import base64 import json +import logging import os from flask import current_app, Flask, render_template, request @@ -68,6 +69,15 @@ def pubsub_push(): # [END push] +@app.errorhandler(500) +def server_error(e): + logging.exception('An error ocurred 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/managed_vms/sendgrid/main.py b/managed_vms/sendgrid/main.py index 2bee1c106994..43d6b7e38ead 100644 --- a/managed_vms/sendgrid/main.py +++ b/managed_vms/sendgrid/main.py @@ -13,6 +13,7 @@ # limitations under the License. # [START app] +import logging import os from flask import Flask, render_template, request @@ -57,6 +58,15 @@ def send_email(): # [END example] +@app.errorhandler(500) +def server_error(e): + logging.exception('An error ocurred 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/managed_vms/static_files/main.py b/managed_vms/static_files/main.py index 4ae0c71a4dac..297809b4b5e2 100644 --- a/managed_vms/static_files/main.py +++ b/managed_vms/static_files/main.py @@ -13,6 +13,8 @@ # limitations under the License. # [START app] +import logging + from flask import Flask, render_template @@ -24,6 +26,15 @@ def hello(): return render_template('index.html') +@app.errorhandler(500) +def server_error(e): + logging.exception('An error ocurred 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/managed_vms/storage/main.py b/managed_vms/storage/main.py index 26ebb55f7ed8..c3207e60c92b 100644 --- a/managed_vms/storage/main.py +++ b/managed_vms/storage/main.py @@ -13,6 +13,7 @@ # limitations under the License. # [START app] +import logging import os from flask import Flask, request @@ -30,7 +31,6 @@ # [START form] @app.route('/') def index(): - """Present the user with an upload form.""" return """
@@ -68,6 +68,15 @@ def upload(): # [END upload] +@app.errorhandler(500) +def server_error(e): + logging.exception('An error ocurred 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/managed_vms/twilio/main.py b/managed_vms/twilio/main.py index 3bbe2caec94a..d3279d80a7ad 100644 --- a/managed_vms/twilio/main.py +++ b/managed_vms/twilio/main.py @@ -13,6 +13,7 @@ # limitations under the License. # [START app] +import logging import os from flask import Flask, request @@ -73,6 +74,15 @@ def receive_sms(): # [END receive_sms] +@app.errorhandler(500) +def server_error(e): + logging.exception('An error ocurred 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/managed_vms/websockets/main.py b/managed_vms/websockets/main.py index 5e6905088407..857e93907ab9 100644 --- a/managed_vms/websockets/main.py +++ b/managed_vms/websockets/main.py @@ -63,6 +63,16 @@ def index(): return render_template('index.html', external_ip=external_ip) # [END app] + +@app.errorhandler(500) +def server_error(e): + logging.exception('An error ocurred during a request.') + return """ + An internal error occurred:
{}
+ See logs for full stacktrace. + """.format(e), 500 + + if __name__ == '__main__': print(""" This can not be run directly because the Flask development server does not