Ejemplo n.º 1
0
    def report_exception(self, exc):
        query = formatting.key_value_list(request.query.allitems())
        forms = formatting.key_value_list(
            self._censor_passwords(request.forms.allitems()) if request.json is None else []
        )
        body = formatting.verbose_pretty_json(request.json)
        local_vars = formatting.key_value_list(
            self._censor_passwords(server_util.exc_frame_locals().items())
        )
        aux_info = textwrap.dedent(
            """\
                    Query params:
                    {0}

                    Form params:
                    {1}

                    JSON body:
                    {2}

                    Local variables:
                    {3}"""
        ).format(query, forms, body, local_vars)

        if len(aux_info) > self.MAX_AUX_INFO_LENGTH:
            aux_info = (
                aux_info[: (self.MAX_AUX_INFO_LENGTH // 2)]
                + "(...truncated...)"
                + aux_info[-(self.MAX_AUX_INFO_LENGTH // 2) :]
            )

        message = textwrap.dedent(
            """\
             Error on request by {0.user}:

             {0.method} {0.path}

             {1}

             {2}"""
        ).format(request, aux_info, traceback.format_exc())

        # Both print to console and send email
        print(message, file=sys.stderr)
        self.send_email(exc, message)
Ejemplo n.º 2
0
    def report_exception(self, exc):
        query = formatting.key_value_list(request.query.allitems())
        forms = formatting.key_value_list(
            self._censor_passwords(request.forms.allitems()) if request.json is None else []
        )
        body = formatting.verbose_pretty_json(request.json)
        local_vars = formatting.key_value_list(
            self._censor_passwords(server_util.exc_frame_locals().items())
        )
        aux_info = textwrap.dedent(
            """\
                    Query params:
                    {0}

                    Form params:
                    {1}

                    JSON body:
                    {2}

                    Local variables:
                    {3}"""
        ).format(query, forms, body, local_vars)

        if len(aux_info) > self.MAX_AUX_INFO_LENGTH:
            aux_info = (
                aux_info[: (self.MAX_AUX_INFO_LENGTH / 2)]
                + "(...truncated...)"
                + aux_info[-(self.MAX_AUX_INFO_LENGTH / 2) :]
            )

        message = textwrap.dedent(
            """\
             Error on request by {0.user}:

             {0.method} {0.path}

             {1}

             {2}"""
        ).format(request, aux_info, traceback.format_exc())

        # Both print to console and send email
        print >>sys.stderr, message
        self.send_email(exc, message)