How to force browser to reroute on a login page on cookie expiration

I’ve developped a fastapi/httpx reverse proxy between my browser & a backend tw5.
Once a custom cookie expires I want the reverse proxy to instruct the tw5 javascript code to reroute to a /login page
I’ve tried

  1. a simple redirect (302/307) back to the tw5 client in the browser. But this does not work. I get the error
Network Error
It looks like the connection to the server has been lost. This may indicate a problem with your network connection. Please attempt to restore network connectivity before continuing.
  1. a retun 401 with instruction to reroute to login
return JSONResponse(
            status_code=401,
            content={"detail": "Unauthorized", "redirect_to": f"{AUTH_SERVER_URL}/login"}
        )
Sync error while processing save of 'ContactSearchInput': XMLHttpRequest error code: 401

Any Idea how I could force the browser to point to a /login page based on a response sent by a reverse proxy in the middle ?

Thanks a lot for your support

Regards

Vpl