littlefish/lfsmailer.py
def add_details(self, message):
        """
        Add extra details to the message.  Separate so that it can be overridden
        """
        msg = message
        # Try to append Flask request details
        try:
            from flask import request
            url = request.url
            method = request.method
            endpoint = request.endpoint

            # Obscure password field and prettify a little bit
            form_dict = dict(request.form)
            for key in form_dict:
                if key.lower() in _error_reporting_obscured_fields:
                    form_dict[key] = '******'
                elif len(form_dict[key]) == 1:
                    form_dict[key] = form_dict[key][0]

            form = pprint.pformat(form_dict).replace('\n', '\n          ')

            msg = '%s\nRequest:\n\nurl:      %s\nmethod:   %s\nendpoint: %s\nform:     %s\n' % \
                (msg, url, method, endpoint, form)
        except Exception:
            traceback.print_exc()

        # Try to append the session
        try:
            from flask import session
            from flask.json import JSONEncoder
            session_str = json.dumps(
                dict(**session),
                indent=2,
                cls=JSONEncoder
            )
            msg = '%s\nSession:\n\n%s\n' % (msg, session_str)
        except Exception:
            traceback.print_exc()
        
        return msg
def add_details(self, message):
        """
        Add extra details to the message.  Separate so that it can be overridden
        """
        msg = message
        # Try to append Flask request details
        try:
            from flask import request
            url = request.url
            method = request.method
            endpoint = request.endpoint

            # Obscure password field and prettify a little bit
            form_dict = dict(request.form)
            for key in form_dict:
                if key.lower() in _error_reporting_obscured_fields:
                    form_dict[key] = '******'
                elif len(form_dict[key]) == 1:
                    form_dict[key] = form_dict[key][0]

            form = pprint.pformat(form_dict).replace('\n', '\n          ')

            msg = '%s\nRequest:\n\nurl:      %s\nmethod:   %s\nendpoint: %s\nform:     %s\n' % \
                (msg, url, method, endpoint, form)
        except Exception:
            traceback.print_exc()

        # Try to append the session
        try:
            from flask import session
            from flask.json import JSONEncoder
            session_str = json.dumps(
                dict(**session),
                indent=2,
                cls=JSONEncoder
            )
            msg = '%s\nSession:\n\n%s\n' % (msg, session_str)
        except Exception:
            traceback.print_exc()
        
        return msg
Add extra details to the message.  Separate so that it can be overridden