simplesite icon indicating copy to clipboard operation
simplesite copied to clipboard

The hx-request header creates error when using back button in browser

Open tataraba opened this issue 1 year ago • 0 comments

On 04_htmx branch:

When visiting the "/catalog" endpoint, artist cards are generated. An htmx event toggles from Artist/Members to Artist/Profile displayed (see below):

image

Clicking on the "MORE INFO" link sends you outside of the app (but it also triggers an hx-request). Since this is an hx-request, it triggers this bit of code in routes.py:

if request.headers.get("hx-request"):
        id = request.headers.get("HX-Trigger")
        artist = db.find("id", int(id))
        print(artist)
        return templates.TemplateResponse(
            "artist/profile.html",
            {
                "request": request,
                "artist": artist[0],
                "get_website": get_website,
                "get_profile": get_profile,
            }
        )

At this point, there is no longer an HX-Trigger, which means that the db.find("id", int(id)) is creating a ValueError.

When a user uses the "back" button in their browser to return to the "/catalog" endpoint, they receive an Internal Server Error.

May be able to fix by adding condition to check for "HX-Trigger", but need to make sure response is correct for what the user is trying to do.

tataraba avatar Mar 27 '23 17:03 tataraba