コード例 #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
ファイル: errors.py プロジェクト: nop33/indico
def handle_http_exception(exc):
    if not (400 <= exc.code <= 599):
        # if it's not an actual error, use it as a response.
        # this is needed e.g. for the 301 redirects that are raised
        # as routing exceptions and thus end up here
        return exc
    return render_error(exc, exc.name, get_error_description(exc), exc.code)
コード例 #3
0
 def _processNotFoundError(self, e):
     if isinstance(e, NotFound):
         message = _("Page not found")  # that's a bit nicer than "404: Not Found"
         explanation = get_error_description(e)
     else:
         message = e.getMessage()
         explanation = e.getExplanation()
     return WErrorWSGI((message, explanation)).getHTML()
コード例 #4
0
ファイル: errors.py プロジェクト: indico/indico
def handle_unprocessableentity(exc):
    data = getattr(exc, 'data', None)
    if data and 'messages' in data and (request.is_xhr or request.is_json):
        # this error came from a webargs parsing failure
        response = jsonify(webargs_errors=data['messages'])
        response.status_code = exc.code
        return response
    if exc.response:
        return exc
    return render_error(exc, exc.name, get_error_description(exc), exc.code)
コード例 #5
0
ファイル: errors.py プロジェクト: bkolobara/indico
def handle_http_exception(exc):
    if not (400 <= exc.code <= 599):
        # if it's not an actual error, use it as a response.
        # this is needed e.g. for the 301 redirects that are raised
        # as routing exceptions and thus end up here
        return exc
    elif exc.response:
        # if the exception has a custom response, we always use that
        # one instead of showing the default error page
        return exc
    return render_error(exc, exc.name, get_error_description(exc), exc.code)
コード例 #6
0
ファイル: errors.py プロジェクト: bkolobara/indico
def handle_notfound(exc):
    try:
        if re.search(r'\.py(?:/\S+)?$', request.path):
            # While not dangerous per se, we never serve *.py files as static
            raise NotFound
        htdocs = os.path.join(current_app.root_path, 'htdocs')
        try:
            return send_from_directory(htdocs, request.path[1:], conditional=True)
        except (UnicodeEncodeError, BadRequest):
            raise NotFound
    except NotFound:
        if exc.description == NotFound.description:
            # The default reason is too long and not localized
            description = get_error_description(exc)
        else:
            description = exc.description
        return render_error(exc, _('Not Found'), description, exc.code)
コード例 #7
0
 def _processForbidden(self, e):
     if session.user is None and not request.is_xhr and not e.response:
         return redirect_to_login(reason=_("Please log in to access this page."))
     message = _("Access Denied")
     explanation = get_error_description(e)
     return WErrorWSGI((message, explanation)).getHTML()
コード例 #8
0
ファイル: errors.py プロジェクト: openprojects/indico
def handle_forbidden(exc):
    if session.user is None and not request.is_xhr and not exc.response and request.blueprint != 'auth':
        return redirect_to_login(
            reason=_('Please log in to access this page.'))
    return render_error(exc, _('Access Denied'), get_error_description(exc),
                        exc.code)
コード例 #9
0
ファイル: errors.py プロジェクト: bkolobara/indico
def handle_forbidden(exc):
    if exc.response:
        return exc
    if session.user is None and not request.is_xhr and request.blueprint != 'auth':
        return redirect_to_login(reason=_('Please log in to access this page.'))
    return render_error(exc, _('Access Denied'), get_error_description(exc), exc.code)
コード例 #10
0
ファイル: base.py プロジェクト: nyimbi/indico
 def _processForbidden(self, e):
     if session.user is None and not request.is_xhr and not e.response and request.blueprint != 'auth':
         return redirect_to_login(reason=_("Please log in to access this page."))
     message = _("Access Denied")
     explanation = get_error_description(e)
     return render_error(message, explanation)