Skip to content

Commit ad6e6bf

Browse files
committed
fix(auth): surface 'No token' dispatch failure as AuthError::NoToken
When a session expires mid-chat, the AWS SDK returns a dispatch failure with 'No token' in the error chain. This was converted to ChatError::Client and displayed as an opaque multi-line error instead of the clear 'Your session has expired. Run q login' message. Add is_no_token_error() to walk the error source chain and detect this case, converting it to ChatError::Auth(AuthError::NoToken) so the existing handler in handle_chat_error displays the actionable message. Fixes #3173
1 parent e14ea18 commit ad6e6bf

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

  • crates/chat-cli/src/cli/chat

crates/chat-cli/src/cli/chat/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,10 +624,31 @@ impl ReasonCode for ChatError {
624624

625625
impl From<ApiClientError> for ChatError {
626626
fn from(value: ApiClientError) -> Self {
627+
// A dispatch failure with "No token" in the error chain means the session has
628+
// expired. Surface this as AuthError::NoToken so the handler in handle_chat_error
629+
// can display a clear "run `q login`" message instead of an opaque SDK error.
630+
// See: #3173
631+
if is_no_token_error(&value) {
632+
return Self::Auth(crate::auth::AuthError::NoToken);
633+
}
627634
Self::Client(Box::new(value))
628635
}
629636
}
630637

638+
/// Returns true if the error chain contains a "No token" dispatch failure,
639+
/// which indicates the user's session has expired.
640+
fn is_no_token_error(err: &ApiClientError) -> bool {
641+
use std::error::Error;
642+
let mut source: Option<&dyn Error> = Some(err);
643+
while let Some(e) = source {
644+
if e.to_string().contains("No token") {
645+
return true;
646+
}
647+
source = e.source();
648+
}
649+
false
650+
}
651+
631652
impl From<parser::SendMessageError> for ChatError {
632653
fn from(value: parser::SendMessageError) -> Self {
633654
Self::SendMessage(Box::new(value))

0 commit comments

Comments
 (0)