Skip to content

Commit d5ebd7a

Browse files
author
Bob Strahan
committed
simply exception catching in bedrock client
1 parent 18a2d88 commit d5ebd7a

File tree

1 file changed

+2
-38
lines changed
  • lib/idp_common_pkg/idp_common/bedrock

1 file changed

+2
-38
lines changed

lib/idp_common_pkg/idp_common/bedrock/client.py

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -450,47 +450,10 @@ def _invoke_with_retry(
450450

451451
return response_with_metering
452452

453-
# except ClientError as e:
454-
except ReadTimeoutError as e
455-
error_code = "ReadTimeoutError"
456-
error_message = str(e)
457-
458-
self._put_metric('BedrockThrottles', 1)
459-
460-
# Check if we've reached max retries
461-
if retry_count >= max_retries:
462-
logger.error(f"Max retries ({max_retries}) exceeded. Last error: {error_message}")
463-
self._put_metric('BedrockRequestsFailed', 1)
464-
self._put_metric('BedrockMaxRetriesExceeded', 1)
465-
raise
466-
467-
# Calculate backoff time
468-
backoff = self._calculate_backoff(retry_count)
469-
logger.warning(f"Bedrock throttling occurred (attempt {retry_count + 1}/{max_retries}). "
470-
f"Error: {error_message}. "
471-
f"Backing off for {backoff:.2f}s")
472-
473-
# Sleep for backoff period
474-
time.sleep(backoff)
475-
476-
# Recursive call with incremented retry count
477-
return self._invoke_with_retry(
478-
converse_params=converse_params,
479-
retry_count=retry_count + 1,
480-
max_retries=max_retries,
481-
request_start_time=request_start_time,
482-
last_exception=e,
483-
context=context
484-
)
485453
except Exception as e:
486-
# logger.error(f"Unexpected error invoking Bedrock: {str(e)}", exc_info=True)
487-
self._put_metric('BedrockRequestsFailed', 1)
488-
self._put_metric('BedrockUnexpectedErrors', 1)
489-
490-
# error_code = type(e)
491454
error_code = e.response['Error']['Code']
492455
error_message = e.response['Error']['Message']
493-
456+
494457
retryable_errors = [
495458
'ThrottlingException',
496459
'ServiceQuotaExceededException',
@@ -537,6 +500,7 @@ def _invoke_with_retry(
537500
self._put_metric('BedrockRequestsFailed', 1)
538501
self._put_metric('BedrockNonRetryableErrors', 1)
539502
raise
503+
540504

541505
def get_guardrail_config(self) -> Optional[Dict[str, str]]:
542506
"""

0 commit comments

Comments
 (0)