fix(auth): handle session expiration and re-authentication in Nous Portal
Enhanced error handling in the _model_flow_nous function to detect session expiration and prompt for re-authentication with the Nous Portal. Added logic to manage re-login attempts and provide user feedback on success or failure, improving the overall user experience during authentication issues.
This commit is contained in:
parent
e5893075f9
commit
7b38afc179
1 changed files with 14 additions and 0 deletions
|
|
@ -498,7 +498,21 @@ def _model_flow_nous(config, current_model=""):
|
||||||
api_key=creds.get("api_key", ""),
|
api_key=creds.get("api_key", ""),
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
relogin = isinstance(exc, AuthError) and exc.relogin_required
|
||||||
msg = format_auth_error(exc) if isinstance(exc, AuthError) else str(exc)
|
msg = format_auth_error(exc) if isinstance(exc, AuthError) else str(exc)
|
||||||
|
if relogin:
|
||||||
|
print(f"Session expired: {msg}")
|
||||||
|
print("Re-authenticating with Nous Portal...\n")
|
||||||
|
try:
|
||||||
|
mock_args = argparse.Namespace(
|
||||||
|
portal_url=None, inference_url=None, client_id=None,
|
||||||
|
scope=None, no_browser=False, timeout=15.0,
|
||||||
|
ca_bundle=None, insecure=False,
|
||||||
|
)
|
||||||
|
_login_nous(mock_args, PROVIDER_REGISTRY["nous"])
|
||||||
|
except Exception as login_exc:
|
||||||
|
print(f"Re-login failed: {login_exc}")
|
||||||
|
return
|
||||||
print(f"Could not fetch models: {msg}")
|
print(f"Could not fetch models: {msg}")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue