diff --git a/managed_vms/analytics/main.py b/managed_vms/analytics/main.py index 49649705762..b12c8cc5488 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 baff9df43f9..f3ba7a41d61 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 c924ae6d453..9c5b06b5c13 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 ee5c9ed5018..f4ec27fb611 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 1c75a7bbff2..d302052ce6b 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 e9bc3eacfa1..5fd2c3718f5 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 0ba388bccea..140c24c9304 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 3cda68026a0..77b790a4f5c 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 f9b3893fb4a..f813b823c17 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 2bee1c10699..43d6b7e38ea 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 4ae0c71a4da..297809b4b5e 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 26ebb55f7ed..c3207e60c92 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 """