Skip to content

Commit

Permalink
error_handlers: Allow appending request body to all error reports
Browse files Browse the repository at this point in the history
  • Loading branch information
dezhidki committed Nov 7, 2022
1 parent 7cb883e commit 336723d
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions timApp/util/error_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@
from typing import Callable, Any

import filelock
from flask import request, render_template, session, flash, Flask, redirect
from flask import (
request,
render_template,
session,
flash,
Flask,
redirect,
has_request_context,
)
from flask.typing import ResponseReturnValue
from markupsafe import Markup # type: ignore
from marshmallow import ValidationError
Expand Down Expand Up @@ -119,12 +127,13 @@ def _set_error_mute_info(error_code: str, info: ErrorMuteInfo) -> None:
cache[error_code] = info


def report_error(err_msg: str) -> None:
def report_error(err_msg: str, with_http_body: bool = False) -> None:
"""
Log an error and send information about it to the error reporting service.
A full stack trace and an error database code is included in the message.
:param err_msg: Error message to include in the report
:param with_http_body: If true, include HTTP body of the active request
"""
log_error(err_msg)
_, ex, tb_obj = sys.exc_info()
Expand Down Expand Up @@ -161,6 +170,9 @@ def report_error(err_msg: str) -> None:
will_mute_next = True
_set_error_mute_info(error_code, mute_info)

if with_http_body and has_request_context():
err_msg += f"\n\nHTTP Body:\n{get_request_message(include_body=True)}"

message = f"""
Exception happened on {get_current_time()} at {request.url}
Expand Down

0 comments on commit 336723d

Please sign in to comment.