Skip to content

Commit 4e7f369

Browse files
committed
fix(hosting): share temporary token validation guidance
1 parent 509c93e commit 4e7f369

4 files changed

Lines changed: 22 additions & 10 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Show `reflex login` guidance when initial authentication rejects an access token, including instructions to replace or remove an explicit `REFLEX_ACCESS_TOKEN` or `--token` override.
2-
When `reflex cloud whoami` cannot validate a token due to a temporary service or connection failure, suggest retrying instead of replacing credentials.
2+
When `reflex cloud whoami` or a noninteractive cloud command cannot validate a token due to a temporary service or connection failure, suggest retrying instead of replacing credentials.

‎packages/reflex-hosting-cli/src/reflex_cli/utils/hosting.py‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,24 @@ def rejected_token_message(source: TokenSource, err: TokenAccessDeniedError) ->
493493
)
494494

495495

496+
def _token_validation_failure_message(
497+
source: TokenSource, err: TokenValidationError
498+
) -> str:
499+
"""Describe a temporary validation failure and suggest retrying.
500+
501+
Args:
502+
source: Where the token was loaded from.
503+
err: The validation error.
504+
505+
Returns:
506+
The message to report.
507+
"""
508+
return (
509+
f"Unable to validate the access token from the {source.value}: "
510+
f"{err} (auth request id: {err.request_id}). Please try again later."
511+
)
512+
513+
496514
def get_existing_access_token() -> str:
497515
"""Fetch the access token from the existing config if applicable.
498516
@@ -932,10 +950,7 @@ def get_authenticated_client(
932950
raise click.exceptions.Exit(1) from err
933951
except TokenValidationError as err:
934952
api.close()
935-
logger.error(
936-
f"Unable to validate the access token from the {source.value}: "
937-
f"{err} (auth request id: {err.request_id})"
938-
)
953+
logger.error(_token_validation_failure_message(source, err))
939954
raise click.exceptions.Exit(1) from err
940955
return AuthenticatedClient(api, me)
941956

‎packages/reflex-hosting-cli/src/reflex_cli/v2/auth.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,7 @@ def whoami_command(token: str | None, loglevel: str, as_json: bool):
110110
logger.error(hosting.rejected_token_message(source, err))
111111
raise click.exceptions.Exit(1) from err
112112
except TokenValidationError as err:
113-
logger.error(
114-
f"Unable to validate the access token from the {source.value}: "
115-
f"{err} (auth request id: {err.request_id}). Please try again later."
116-
)
113+
logger.error(hosting._token_validation_failure_message(source, err))
117114
raise click.exceptions.Exit(1) from err
118115

119116
identity = {

‎tests/units/reflex_cli/utils/test_hosting.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ def test_unvalidated_token_in_non_interactive_mode_is_not_called_rejected(
588588
browser.assert_not_called()
589589
errors = [r.getMessage() for r in caplog.records if r.levelno == logging.ERROR]
590590
assert errors == [
591-
"Unable to validate the access token from the config file: server error (auth request id: req-2)"
591+
"Unable to validate the access token from the config file: server error (auth request id: req-2). Please try again later."
592592
]
593593

594594

0 commit comments

Comments
 (0)