Skip to content

Commit 04407b2

Browse files
committed
error handling
1 parent e52a1b6 commit 04407b2

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

crates/chat-cli/src/api_client/clients/streaming_client.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ impl StreamingClient {
139139

140140
match &self.inner {
141141
inner::Inner::Codewhisperer(client) => {
142+
let model_id_opt: Option<String> = user_input_message.model_id.clone();
142143
let conversation_state = amzn_codewhisperer_streaming_client::types::ConversationState::builder()
143144
.set_conversation_id(conversation_id)
144145
.current_message(
@@ -170,10 +171,18 @@ impl StreamingClient {
170171
&& err.meta().message() == Some("Input is too long."))
171172
});
172173

174+
let is_model_unavailable = model_id_opt.is_some()
175+
&& e.raw_response().is_some_and(|resp| resp.status().as_u16() == 500)
176+
&& e.as_service_error().is_some_and(|err| {
177+
err.meta().message()
178+
== Some("Encountered unexpectedly high load when processing the request, please try again.".into())
179+
});
173180
if is_quota_breach {
174181
Err(ApiClientError::QuotaBreach("quota has reached its limit"))
175182
} else if is_context_window_overflow {
176183
Err(ApiClientError::ContextWindowOverflow)
184+
} else if is_model_unavailable {
185+
Err(ApiClientError::ModelOverloadedError())
177186
} else {
178187
Err(e.into())
179188
}

crates/chat-cli/src/api_client/error.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ pub enum ApiClientError {
6565

6666
#[error(transparent)]
6767
AuthError(#[from] AuthError),
68+
69+
#[error(
70+
"The model you've selected is temporarily unavailable. Please use '/model' to select a different model and try again."
71+
)]
72+
ModelOverloadedError(),
6873
}
6974

7075
#[cfg(test)]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ impl ConversationState {
606606
user_input_message_context: None,
607607
user_intent: None,
608608
images: None,
609-
model_id: self.current_model_id.to_owned(),
609+
model_id: self.current_model_id.clone(),
610610
};
611611

612612
// If the last message contains tool uses, then add cancelled tool results to the summary

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ impl ChatArgs {
282282
let model_id: Option<String> = if let Some(model_name) = self.model {
283283
let model_name_lower = model_name.to_lowercase();
284284
match MODEL_OPTIONS.iter().find(|(_, name, _)| name == &model_name_lower) {
285-
Some((_, _, id)) => Some(id.to_string()),
285+
Some((_, _, id)) => Some((*id).to_string()),
286286
None => {
287287
let available_names: Vec<&str> = MODEL_OPTIONS.iter().map(|(_, name, _)| *name).collect();
288288
bail!(

0 commit comments

Comments
 (0)