Help for web.app.redirect_error

Project

web.app

Function

redirect_error

Sample CLI

gway web.app redirect-error

References

['debug', 'error', 'exception']

Full Code

def redirect_error(error=None, note="", default="/gway/readme", broken_view_name=None):
    from bottle import request, response
    gw.error("Redirecting due to error." + (" " + note if note else ""))

    gw.error(f"Method: {request.method}")
    gw.error(f"Path: {request.path}")
    gw.error(f"Full URL: {request.url}")
    gw.error(f"Query: {dict(request.query)}")

    try:
        if request.json:
            gw.error(f"JSON body: {request.json}")
        elif request.forms:
            gw.error(f"Form data: {request.forms.decode()}")
    except Exception as e:
        gw.exception(e)

    gw.error(f"Headers: {dict(request.headers)}")
    gw.error(f"Cookies: {request.cookies}")

    if error:
        gw.exception(error)

    if broken_view_name and cookies_enabled():
        gw.debug(f"Removing cookie for {broken_view_name=}")
        raw = request.get_cookie("visited", "")
        visited = raw.split("|") if raw else []
        broken_title = broken_view_name.replace("-", " ").replace("_", " ").title()
        visited = [v for v in visited if not v.startswith(f"{broken_title}=")]
        response.set_cookie("visited", "|".join(visited), path="/")

    response.status = 302
    response.set_header("Location", default)
    return ""