Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add crash header to 500 responses #114

Merged
merged 1 commit into from
Feb 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/functions_framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
DEFAULT_SIGNATURE_TYPE = "http"
MAX_CONTENT_LENGTH = 10 * 1024 * 1024

_FUNCTION_STATUS_HEADER_FIELD = "X-Google-Status"
_CRASH = "crash"


class _Event(object):
"""Event passed to background functions."""
Expand Down Expand Up @@ -160,6 +163,13 @@ def read_request(response):
return response


def crash_handler(e):
"""
Return crash header to allow logging 'crash' message in logs.
"""
return str(e), 500, {_FUNCTION_STATUS_HEADER_FIELD: _CRASH}


def create_app(target=None, source=None, signature_type=None):
# Get the configured function target
target = target or os.environ.get("FUNCTION_TARGET", "")
Expand Down Expand Up @@ -215,6 +225,7 @@ def create_app(target=None, source=None, signature_type=None):
# 5. Create the application
app = flask.Flask(target, template_folder=template_folder)
app.config["MAX_CONTENT_LENGTH"] = MAX_CONTENT_LENGTH
app.register_error_handler(500, crash_handler)
di marked this conversation as resolved.
Show resolved Hide resolved
global errorhandler
errorhandler = app.errorhandler

Expand Down