Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
def handle_validationerror(exc):
    # marshmallow validation failed outside webargs
    if request.is_xhr or request.is_json:
        # this error came from a webargs parsing failure
        response = jsonify(webargs_errors=exc.messages)
        response.status_code = 422
        return response
    return render_error(exc, exc.name, get_error_description(exc), 422)
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
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)
Exemplo n.º 8
0
def handle_exception(exc, message=None):
    Logger.get('flask').exception(to_unicode(exc.message) or 'Uncaught Exception')
    if not current_app.debug or request.is_xhr or request.is_json:
        sentry_log_exception()
        if message is None:
            message = '{}: {}'.format(type(exc).__name__, to_unicode(exc.message))
        return render_error(exc, _('Something went wrong'), message, 500)
    # Let the exception propagate to middleware /the webserver.
    # This triggers the Flask debugger in development and sentry
    # logging (if enabled) (via got_request_exception).
    raise
Exemplo n.º 9
0
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)
Exemplo n.º 10
0
def handle_exception(exc, message=None):
    Logger.get('flask').exception(to_unicode(exc.message) or 'Uncaught Exception')
    if not current_app.debug or request.is_xhr or request.is_json:
        sentry_log_exception()
        if message is None:
            message = '{}: {}'.format(type(exc).__name__, to_unicode(exc.message))
        return render_error(exc, _('Something went wrong'), message, 500)
    # Let the exception propagate to middleware /the webserver.
    # This triggers the Flask debugger in development and sentry
    # logging (if enabled) (via got_request_exception).
    raise
Exemplo n.º 11
0
def handle_exception(exc, message=None):
    Logger.get('flask').exception(str(exc) or 'Uncaught Exception')
    if not current_app.debug or request.is_xhr or request.is_json:
        sentry_sdk.capture_exception(exc)
        if message is None:
            message = '{}: {}'.format(type(exc).__name__, str(exc))
        if os.environ.get('INDICO_DEV_SERVER') == '1':
            # If we are in the dev server, we always want to see a traceback on the
            # console, even if this was an API request.
            traceback.print_exc()
        return render_error(exc, _('Something went wrong'), message, 500)
    # Let the exception propagate to middleware / the webserver.
    # This triggers the Flask debugger in development and sentry
    # logging (if enabled) (via got_request_exception).
    raise
Exemplo n.º 12
0
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)
Exemplo n.º 13
0
def handle_indico_exception(exc):
    return render_error(exc, _('Something went wrong'), str(exc),
                        getattr(exc, 'http_status_code', 500))
Exemplo n.º 14
0
def handle_baddata(exc):
    return render_error(exc, _('Invalid or expired token'), str(exc), 400)
Exemplo n.º 15
0
def handle_badrequestkeyerror(exc):
    if current_app.debug:
        raise
    msg = _('Required argument missing: {}').format(str(exc))
    return render_error(exc, exc.name, msg, exc.code)
Exemplo n.º 16
0
def handle_baddata(exc):
    return render_error(exc, _('Invalid or expired token'),
                        to_unicode(exc.message), 400)
Exemplo n.º 17
0
def handle_indico_exception(exc):
    return render_error(exc, _('Something went wrong'), to_unicode(exc.message), getattr(exc, 'http_status_code', 500))
Exemplo n.º 18
0
def handle_baddata(exc):
    return render_error(exc, _('Invalid or expired token'), to_unicode(exc.message), 400)
Exemplo n.º 19
0
def handle_badrequestkeyerror(exc):
    if current_app.debug:
        raise
    msg = _('Required argument missing: {}').format(to_unicode(exc.message))
    return render_error(exc, exc.name, msg, exc.code)
Exemplo n.º 20
0
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)