From b368fc31494dab4bef75c59304c22728433274fc Mon Sep 17 00:00:00 2001 From: Wilson Huang Date: Fri, 22 Nov 2024 13:45:05 -0500 Subject: [PATCH] fix(amazonq): add throttling exception handling and in code comments for featureDev quota --- .../amazonqFeatureDev/client/featureDev.ts | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/packages/core/src/amazonqFeatureDev/client/featureDev.ts b/packages/core/src/amazonqFeatureDev/client/featureDev.ts index fa0f3ba054b..909fa33627c 100644 --- a/packages/core/src/amazonqFeatureDev/client/featureDev.ts +++ b/packages/core/src/amazonqFeatureDev/client/featureDev.ts @@ -78,7 +78,11 @@ export class FeatureDevClient { getLogger().error( `${featureName}: failed to start conversation: ${e.message} RequestId: ${e.requestId}` ) - if (e.code === 'ServiceQuotaExceededException') { + // BE service will throw ServiceQuota if conversation limit is reached. API Front-end will throw Throttling with this message if conversation limit is reached + if ( + e.code === 'ServiceQuotaExceededException' || + (e.code === 'ThrottlingException' && e.message.includes('reached for this month.')) + ) { throw new MonthlyConversationLimitError(e.message) } throw new ApiError(e.message, 'CreateConversation', e.code, e.statusCode ?? 400) @@ -167,14 +171,22 @@ export class FeatureDevClient { (e as any).requestId }` ) - if ( - isAwsError(e) && - ((e.code === 'ThrottlingException' && - e.message.includes('limit for number of iterations on a code generation')) || - e.message.includes('StartTaskAssistCodeGeneration reached for this month.') || - e.code === 'ServiceQuotaExceededException') - ) { - throw new CodeIterationLimitError() + if (isAwsError(e)) { + // API Front-end will throw Throttling if conversation limit is reached. API Front-end monitors StartCodeGeneration for throttling + if ( + e.code === 'ThrottlingException' && + e.message.includes('StartTaskAssistCodeGeneration reached for this month.') + ) { + throw new MonthlyConversationLimitError(e.message) + } + // BE service will throw ServiceQuota if code generation iteration limit is reached + else if ( + e.code === 'ServiceQuotaExceededException' || + (e.code === 'ThrottlingException' && + e.message.includes('limit for number of iterations on a code generation')) + ) { + throw new CodeIterationLimitError() + } } throw new ToolkitError((e as Error).message, { code: 'StartCodeGenerationFailed' }) }