Skip to content

Commit

Permalink
Adding error handlers to all managed vms samples.
Browse files Browse the repository at this point in the history
Change-Id: I1010699be5bbbf5f8356e2a0a27e0c2f836fdaf9
  • Loading branch information
Jon Wayne Parrott committed Apr 26, 2016
1 parent 53373b1 commit e005341
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 1 deletion.
10 changes: 10 additions & 0 deletions managed_vms/analytics/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

# [START app]
import logging
import os

from flask import Flask
Expand Down Expand Up @@ -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: <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
10 changes: 10 additions & 0 deletions managed_vms/cloudsql/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import datetime
import logging
import os
import socket

Expand Down Expand Up @@ -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: <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
10 changes: 10 additions & 0 deletions managed_vms/datastore/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import datetime
import logging
import os
import socket

Expand Down Expand Up @@ -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: <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
10 changes: 10 additions & 0 deletions managed_vms/disk/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import os
import socket

Expand Down Expand Up @@ -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: <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
10 changes: 10 additions & 0 deletions managed_vms/extending_runtime/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

# [START app]
import logging
import subprocess

from flask import Flask
Expand All @@ -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: <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 CMD in Dockerfile.
Expand Down
11 changes: 11 additions & 0 deletions managed_vms/extending_runtime_compat/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

# [START app]
import logging
import subprocess

from flask import Flask
Expand All @@ -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: <pre>{}</pre>
See logs for full stacktrace.
""".format(e), 500

# [END app]
10 changes: 10 additions & 0 deletions managed_vms/mailgun/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

# [START app]
import logging
import os

from flask import Flask, render_template, request
Expand Down Expand Up @@ -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: <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
10 changes: 10 additions & 0 deletions managed_vms/memcache/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: <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
10 changes: 10 additions & 0 deletions managed_vms/pubsub/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# [START app]
import base64
import json
import logging
import os

from flask import current_app, Flask, render_template, request
Expand Down Expand Up @@ -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: <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
10 changes: 10 additions & 0 deletions managed_vms/sendgrid/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

# [START app]
import logging
import os

from flask import Flask, render_template, request
Expand Down Expand Up @@ -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: <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 managed_vms/static_files/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, render_template


Expand All @@ -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: <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: 10 additions & 1 deletion managed_vms/storage/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

# [START app]
import logging
import os

from flask import Flask, request
Expand All @@ -30,7 +31,6 @@
# [START form]
@app.route('/')
def index():
"""Present the user with an upload form."""
return """
<form method="POST" action="/upload" enctype="multipart/form-data">
<input type="file" name="file">
Expand Down Expand Up @@ -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: <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
10 changes: 10 additions & 0 deletions managed_vms/twilio/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

# [START app]
import logging
import os

from flask import Flask, request
Expand Down Expand Up @@ -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: <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
10 changes: 10 additions & 0 deletions managed_vms/websockets/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: <pre>{}</pre>
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
Expand Down

0 comments on commit e005341

Please sign in to comment.