예제 #1
0
파일: json.py 프로젝트: hennogous/indico
def create_json_error_answer(exception, status=200):
    from indico.core.config import Config
    from indico.core.errors import IndicoError, get_error_description
    if isinstance(exception, IndicoError):
        details = exception.toDict()
    else:
        exception_data = exception.__dict__
        try:
            _json.dumps(exception_data)
        except Exception:
            exception_data = {}
        details = {
            'code': type(exception).__name__,
            'type': 'noReport' if ((not session.user and isinstance(exception, Forbidden)) or
                                   _is_no_report_error(exception)) else 'unknown',
            'message': unicode(get_error_description(exception)),
            'data': exception_data,
            'requestInfo': get_request_info(),
            'inner': traceback.format_exc()
        }

    return current_app.response_class(dumps({
        'version': Config.getInstance().getVersion(),
        'result': None,
        'error': details
    }), mimetype='application/json', status=status)
예제 #2
0
def create_json_error_answer(exception, status=200):
    from indico.core.errors import IndicoError, get_error_description
    if isinstance(exception, IndicoError):
        details = exception.toDict()
    else:
        exception_data = exception.__dict__
        try:
            _json.dumps(exception_data)
        except Exception:
            exception_data = {}
        details = {
            'code': type(exception).__name__,
            'hasUser': bool(session.user),
            'type': 'noReport' if ((not session.user and isinstance(exception, Forbidden)) or
                                   _is_no_report_error(exception)) else 'unknown',
            'message': unicode(get_error_description(exception)),
            'data': exception_data,
            'requestInfo': get_request_info(),
            'inner': traceback.format_exc()
        }

    return current_app.response_class(dumps({
        'version': indico.__version__,
        'result': None,
        'error': details
    }), mimetype='application/json', status=status)
예제 #3
0
파일: json.py 프로젝트: k3njiy/indico
def create_json_error_answer(exception, status=200):
    from indico.core.config import Config
    from indico.core.errors import IndicoError
    if isinstance(exception, IndicoError):
        details = exception.toDict()
    else:
        exception_data = exception.__dict__
        try:
            _json.dumps(exception_data)
        except Exception:
            exception_data = {}
        details = {
            'code': type(exception).__name__,
            'type': 'unknown',
            # werkzeug HTTPExceptions have a description instead of a message.
            'message': unicode(getattr(exception, 'description', exception.message)),
            'data': exception_data,
            'requestInfo': get_request_info(),
            'inner': traceback.format_exc()
        }

    return current_app.response_class(dumps({
        'version': Config.getInstance().getVersion(),
        'result': None,
        'error': details
    }), mimetype='application/json', status=status)
예제 #4
0
파일: errors.py 프로젝트: bkolobara/indico
def _save_error(exc, title, message):
    # Note that `exc` is only used to check if the error should be saved.
    # Any other information is taken from `sys.exc_info()`!
    if 'saved_error_uuid' in g:
        return
    if not _is_error_reportable(exc):
        return
    g.saved_error_uuid = uuid = unicode(uuid4())
    # XXX: keep this outside - it must be called before `get_request_info()`
    # as that function may mess up `sys.exc_info()` in case accessing user
    # details fails
    tb = traceback.format_exc()
    data = {'title': title,
            'message': message,
            'request_info': get_request_info(),
            'traceback': tb,
            'sentry_event_id': g.get('sentry_event_id')}
    GenericCache('errors').set(uuid, data, 7200)
예제 #5
0
파일: errors.py 프로젝트: imfht/flaskapps
def _save_error(exc, title, message):
    # Note that `exc` is only used to check if the error should be saved.
    # Any other information is taken from `sys.exc_info()`!
    if 'saved_error_uuid' in g:
        return
    if not _is_error_reportable(exc):
        return
    g.saved_error_uuid = uuid = str(uuid4())
    # XXX: keep this outside - it must be called before `get_request_info()`
    # as that function may mess up `sys.exc_info()` in case accessing user
    # details fails
    tb = traceback.format_exc()
    data = {'title': title,
            'message': message,
            'request_info': get_request_info(),
            'traceback': tb,
            'sentry_event_id': g.get('sentry_event_id')}
    GenericCache('errors').set(uuid, data, 7200)
예제 #6
0
    def getVars( self ):
        vars = WTemplated.getVars( self )
        ex = sys.exc_info()[1]
        vars["msg"] = self.htmlText( str( ex ) )
        vars["area"]= ""
        ty, ex, tb = sys.exc_info()
        tracebackList = traceback.format_list( traceback.extract_tb( tb ) )
        rh = self._rh.__class__
        url = request.url.encode('utf-8')
        params = []
        for (k,v) in self._rh.getRequestParams().items():
            if k.strip() != "password":
                params.append("""%s = %s""" % (self.htmlText(k), self.htmlText(v)))
        headers = []
        for k, v in request.headers.iteritems():
            headers.append("""%s: %s""" % (self.htmlText(k), self.htmlText(v)))
        userHTML = """-- none --"""
        vars["userEmail"] = ""
        av = self._rh.getAW().getUser()
        if av:
            userHTML = self.htmlText( "%s <%s>"%( av.getFullName(), av.getEmail() ) )
            vars["userEmail"] = quoteattr( av.getEmail() )
        vars["reportURL"] = quoteattr( str( urlHandlers.UHErrorReporting.getURL() ) )
        details = ""
        show_details = Config.getInstance().getDebug()
        if not show_details:
            try:
                show_details = session.user and session.user.is_admin
            except Exception:
                # We are handling some error so we cannot know if accessing the session user works
                # If it fails we simply don't show details...
                pass
        if show_details:
            details = """
<table class="errorDetailsBox">
    <tr>
        <td>ERROR DETAILS</td>
    </tr>
    <tr>
        <td><br></td>
    </tr>
    <tr>
        <td nowrap align="right"><b>Exception type:</b></td>
        <td>%s</td>
    </tr>
    <tr>
        <td nowrap align="right" valign="top"><b>Exception message:</b></td>
        <td>%s</td>
    </tr>
    """%( self.htmlText( str(ty) ), self.htmlText( str(ex) ))

            if hasattr(ex, 'problematic_templates') and hasattr(ex, 'template_tracebacks'):
                for i in range(len(ex.problematic_templates)):
                    details +="""
    <tr>
        <td nowrap align="right" valign="top"><b>Traceback for<br>%s.tpl:</b></td>
        <td>%s</td>
    </tr>
                """%(ex.problematic_templates[i], "<br>".join(ex.template_tracebacks[i]))

            details +="""
    <tr>
        <td valign="top" nowrap align="right"><b>Traceback:</b></td>
        <td><pre>%s</pre></td>
    </tr>
    <tr>
        <td nowrap align="right"><b>Request handler:</b></td>
        <td>%s</td>
    </tr>
    <tr>
        <td nowrap align="right"><b>URL:</b></td>
        <td>%s</td>
    </tr>
    <tr>
        <td nowrap align="right" valign="top"><b>Params:</b></td>
        <td>%s</td>
    </tr>
    <tr>
        <td valign="top" nowrap align="right"><b>HTTP headers:</b></td>
        <td><pre>%s</pre></td>
    </tr>
    <tr>
        <td nowrap align="right"><b>Logged user:</b></td>
        <td>%s</td>
    </tr>
</table>
            """%("\n".join( tracebackList ), rh.__name__, url, "<br>".join(params), \
                    "\n".join( headers ), userHTML )
        vars["errorDetails"] = details
        vars["reportMsg"] = quoteattr(json.dumps({'request_info': get_request_info(),
                                                  'traceback': traceback.format_exc()}))
        return vars
예제 #7
0
    def getVars(self):
        vars = WTemplated.getVars(self)
        ex = sys.exc_info()[1]
        vars["msg"] = self.htmlText(str(ex))
        vars["area"] = ""
        ty, ex, tb = sys.exc_info()
        tracebackList = traceback.format_list(traceback.extract_tb(tb))
        rh = self._rh.__class__
        url = request.url.encode('utf-8')
        params = []
        for (k, v) in self._rh.getRequestParams().items():
            if k.strip() != "password":
                params.append("""%s = %s""" %
                              (self.htmlText(k), self.htmlText(v)))
        headers = []
        for k, v in request.headers.iteritems():
            headers.append("""%s: %s""" % (self.htmlText(k), self.htmlText(v)))
        userHTML = """-- none --"""
        vars["userEmail"] = ""
        av = self._rh.getAW().getUser()
        if av:
            userHTML = self.htmlText("%s <%s>" %
                                     (av.getFullName(), av.getEmail()))
            vars["userEmail"] = quoteattr(av.getEmail())
        vars["reportURL"] = quoteattr(
            str(urlHandlers.UHErrorReporting.getURL()))
        details = ""
        show_details = Config.getInstance().getDebug()
        if not show_details:
            try:
                show_details = session.user and session.user.is_admin
            except Exception:
                # We are handling some error so we cannot know if accessing the session user works
                # If it fails we simply don't show details...
                pass
        if show_details:
            details = """
<table class="errorDetailsBox">
    <tr>
        <td>ERROR DETAILS</td>
    </tr>
    <tr>
        <td><br></td>
    </tr>
    <tr>
        <td nowrap align="right"><b>Exception type:</b></td>
        <td>%s</td>
    </tr>
    <tr>
        <td nowrap align="right" valign="top"><b>Exception message:</b></td>
        <td>%s</td>
    </tr>
    """ % (self.htmlText(str(ty)), self.htmlText(str(ex)))

            if hasattr(ex, 'problematic_templates') and hasattr(
                    ex, 'template_tracebacks'):
                for i in range(len(ex.problematic_templates)):
                    details += """
    <tr>
        <td nowrap align="right" valign="top"><b>Traceback for<br>%s.tpl:</b></td>
        <td>%s</td>
    </tr>
                """ % (ex.problematic_templates[i], "<br>".join(
                        ex.template_tracebacks[i]))

            details +="""
    <tr>
        <td valign="top" nowrap align="right"><b>Traceback:</b></td>
        <td><pre>%s</pre></td>
    </tr>
    <tr>
        <td nowrap align="right"><b>Request handler:</b></td>
        <td>%s</td>
    </tr>
    <tr>
        <td nowrap align="right"><b>URL:</b></td>
        <td>%s</td>
    </tr>
    <tr>
        <td nowrap align="right" valign="top"><b>Params:</b></td>
        <td>%s</td>
    </tr>
    <tr>
        <td valign="top" nowrap align="right"><b>HTTP headers:</b></td>
        <td><pre>%s</pre></td>
    </tr>
    <tr>
        <td nowrap align="right"><b>Logged user:</b></td>
        <td>%s</td>
    </tr>
</table>
            """%("\n".join( tracebackList ), rh.__name__, url, "<br>".join(params), \
                    "\n".join( headers ), userHTML )
        vars["errorDetails"] = details
        vars["reportMsg"] = quoteattr(
            json.dumps({
                'request_info': get_request_info(),
                'traceback': traceback.format_exc()
            }))
        return vars
예제 #8
0
 def format(self, record):
     rv = super(RequestInfoFormatter, self).format(record)
     info = get_request_info()
     if info:
         rv += '\n\n' + pformat(info)
     return rv
예제 #9
0
파일: logger.py 프로젝트: bkolobara/indico
 def format(self, record):
     rv = super(RequestInfoFormatter, self).format(record)
     info = get_request_info()
     if info:
         rv += '\n\n' + pformat(info)
     return rv
예제 #10
0
    def getVars(self):
        vars = WTemplated.getVars(self)
        ex = sys.exc_info()[1]
        vars["msg"] = self.htmlText(str(ex))
        vars["area"] = ""
        ty, ex, tb = sys.exc_info()
        tracebackList = traceback.format_list(traceback.extract_tb(tb))
        rh = self._rh.__class__
        url = request.url.encode('utf-8')
        params = []
        for k, v in request.values.iteritems():
            if k.strip() != "password":
                params.append("""%s = %s""" %
                              (self.htmlText(k), self.htmlText(v)))
        headers = []
        for k, v in request.headers.iteritems():
            headers.append("""%s: %s""" % (self.htmlText(k), self.htmlText(v)))
        userHTML = """-- none --"""
        vars["userEmail"] = ""
        try:
            user = session.user
            user_name = user and user.full_name
            user_email = user and user.email
            user_is_admin = user and user.is_admin
        except Exception:
            # Yuck! But we are handling an error and we don't know if we
            # can access the user or its attributes...
            user_is_admin = False
        else:
            if user:
                userHTML = self.htmlText(u'{} <{}>'.format(
                    user_name, user_email).encode('utf-8'))
                vars["userEmail"] = quoteattr(user_email.encode('utf-8'))
        vars["reportURL"] = quoteattr(url_for('misc.errors'))
        details = ""
        if config.DEBUG or user_is_admin:
            details = """
<table class="errorDetailsBox">
    <tr>
        <td>ERROR DETAILS</td>
    </tr>
    <tr>
        <td><br></td>
    </tr>
    <tr>
        <td nowrap align="right"><b>Exception type:</b></td>
        <td>%s</td>
    </tr>
    <tr>
        <td nowrap align="right" valign="top"><b>Exception message:</b></td>
        <td>%s</td>
    </tr>
    """ % (self.htmlText(str(ty)), self.htmlText(str(ex)))

            if hasattr(ex, 'problematic_templates') and hasattr(
                    ex, 'template_tracebacks'):
                for i in range(len(ex.problematic_templates)):
                    details += """
    <tr>
        <td nowrap align="right" valign="top"><b>Traceback for<br>%s.tpl:</b></td>
        <td>%s</td>
    </tr>
                """ % (ex.problematic_templates[i], "<br>".join(
                        ex.template_tracebacks[i]))

            details +="""
    <tr>
        <td valign="top" nowrap align="right"><b>Traceback:</b></td>
        <td><pre>%s</pre></td>
    </tr>
    <tr>
        <td nowrap align="right"><b>Request handler:</b></td>
        <td>%s</td>
    </tr>
    <tr>
        <td nowrap align="right"><b>URL:</b></td>
        <td>%s</td>
    </tr>
    <tr>
        <td nowrap align="right" valign="top"><b>Params:</b></td>
        <td>%s</td>
    </tr>
    <tr>
        <td valign="top" nowrap align="right"><b>HTTP headers:</b></td>
        <td><pre>%s</pre></td>
    </tr>
    <tr>
        <td nowrap align="right"><b>Logged user:</b></td>
        <td>%s</td>
    </tr>
</table>
            """%("\n".join( tracebackList ), rh.__name__, url, "<br>".join(params), \
                    "\n".join( headers ), userHTML )
        vars["errorDetails"] = details
        vars["reportMsg"] = quoteattr(
            json.dumps({
                'request_info': get_request_info(),
                'traceback': traceback.format_exc()
            }))
        return vars
예제 #11
0
파일: logger.py 프로젝트: OmeGak/indico
 def _getRequestInfo(self):
     return "\n\n\nRequest data:\n\n{}".format(pformat(get_request_info()))
예제 #12
0
 def _getRequestInfo(self):
     return '\n\n\nRequest data:\n\n{}'.format(pformat(get_request_info()))