Skip to content

Commit 8aea885

Browse files
chore: update model overloaded error to handle the updated error modeling from the backend (#2396)
1 parent 083e3d9 commit 8aea885

File tree

1 file changed

+48
-16
lines changed
  • crates/chat-cli/src/api_client

1 file changed

+48
-16
lines changed

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

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -285,20 +285,36 @@ impl ApiClient {
285285
{
286286
Ok(response) => Ok(SendMessageOutput::Codewhisperer(response)),
287287
Err(err) => {
288+
use amzn_codewhisperer_streaming_client::operation::generate_assistant_response::GenerateAssistantResponseError::ThrottlingError as OperationThrottlingError;
289+
use amzn_codewhisperer_streaming_client::types::ThrottlingExceptionReason;
290+
use amzn_codewhisperer_streaming_client::types::error::ThrottlingError;
291+
288292
let status_code = err.raw_response().map(|res| res.status().as_u16());
289293
let is_quota_breach = status_code.is_some_and(|status| status == 429);
290294
let is_context_window_overflow = err.as_service_error().is_some_and(|err| {
291295
matches!(err, err if err.meta().code() == Some("ValidationException") && err.meta().message() == Some("Input is too long."))
292296
});
293297

294-
let is_model_unavailable = model_id_opt.is_some()
295-
&& status_code.is_some_and(|status| status == 500)
296-
&& err.as_service_error().is_some_and(|err| {
297-
err.meta().message()
298-
== Some(
299-
"Encountered unexpectedly high load when processing the request, please try again.",
300-
)
301-
});
298+
let is_model_unavailable =
299+
// Handling the updated error response
300+
err.as_service_error().is_some_and(|err| {
301+
matches!(
302+
err,
303+
OperationThrottlingError(ThrottlingError {
304+
reason: Some(ThrottlingExceptionReason::InsufficientModelCapacity),
305+
..
306+
})
307+
)
308+
})
309+
// Legacy error response
310+
|| (model_id_opt.is_some()
311+
&& status_code.is_some_and(|status| status == 500)
312+
&& err.as_service_error().is_some_and(|err| {
313+
err.meta().message()
314+
== Some(
315+
"Encountered unexpectedly high load when processing the request, please try again.",
316+
)
317+
}));
302318

303319
let is_monthly_limit_err = err
304320
.raw_response()
@@ -361,20 +377,36 @@ impl ApiClient {
361377
{
362378
Ok(response) => Ok(SendMessageOutput::QDeveloper(response)),
363379
Err(err) => {
380+
use amzn_qdeveloper_streaming_client::operation::send_message::SendMessageError::ThrottlingError as OperationThrottlingError;
381+
use amzn_qdeveloper_streaming_client::types::ThrottlingExceptionReason;
382+
use amzn_qdeveloper_streaming_client::types::error::ThrottlingError;
383+
364384
let status_code = err.raw_response().map(|res| res.status().as_u16());
365385
let is_quota_breach = status_code.is_some_and(|status| status == 429);
366386
let is_context_window_overflow = err.as_service_error().is_some_and(|err| {
367387
matches!(err, err if err.meta().code() == Some("ValidationException") && err.meta().message() == Some("Input is too long."))
368388
});
369389

370-
let is_model_unavailable = model_id_opt.is_some()
371-
&& status_code.is_some_and(|status| status == 500)
372-
&& err.as_service_error().is_some_and(|err| {
373-
err.meta().message()
374-
== Some(
375-
"Encountered unexpectedly high load when processing the request, please try again.",
376-
)
377-
});
390+
let is_model_unavailable =
391+
// Handling the updated error response
392+
err.as_service_error().is_some_and(|err| {
393+
matches!(
394+
err,
395+
OperationThrottlingError(ThrottlingError {
396+
reason: Some(ThrottlingExceptionReason::InsufficientModelCapacity),
397+
..
398+
})
399+
)
400+
})
401+
// Legacy error response
402+
|| (model_id_opt.is_some()
403+
&& status_code.is_some_and(|status| status == 500)
404+
&& err.as_service_error().is_some_and(|err| {
405+
err.meta().message()
406+
== Some(
407+
"Encountered unexpectedly high load when processing the request, please try again.",
408+
)
409+
}));
378410

379411
let is_monthly_limit_err = err
380412
.raw_response()

0 commit comments

Comments
 (0)