Skip to content

Commit a0de73d

Browse files
authored
fix(amazonq): add throttling exception handling and in code comments for featureDev quota (#6093)
## Problem - Follow up of #6091 - improve and refactor the code from that previous PR ## Solution
1 parent 1a00852 commit a0de73d

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

packages/core/src/amazonqFeatureDev/client/featureDev.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ export class FeatureDevClient {
7878
getLogger().error(
7979
`${featureName}: failed to start conversation: ${e.message} RequestId: ${e.requestId}`
8080
)
81-
if (e.code === 'ServiceQuotaExceededException') {
81+
// BE service will throw ServiceQuota if conversation limit is reached. API Front-end will throw Throttling with this message if conversation limit is reached
82+
if (
83+
e.code === 'ServiceQuotaExceededException' ||
84+
(e.code === 'ThrottlingException' && e.message.includes('reached for this month.'))
85+
) {
8286
throw new MonthlyConversationLimitError(e.message)
8387
}
8488
throw new ApiError(e.message, 'CreateConversation', e.code, e.statusCode ?? 400)
@@ -167,14 +171,22 @@ export class FeatureDevClient {
167171
(e as any).requestId
168172
}`
169173
)
170-
if (
171-
isAwsError(e) &&
172-
((e.code === 'ThrottlingException' &&
173-
e.message.includes('limit for number of iterations on a code generation')) ||
174-
e.message.includes('StartTaskAssistCodeGeneration reached for this month.') ||
175-
e.code === 'ServiceQuotaExceededException')
176-
) {
177-
throw new CodeIterationLimitError()
174+
if (isAwsError(e)) {
175+
// API Front-end will throw Throttling if conversation limit is reached. API Front-end monitors StartCodeGeneration for throttling
176+
if (
177+
e.code === 'ThrottlingException' &&
178+
e.message.includes('StartTaskAssistCodeGeneration reached for this month.')
179+
) {
180+
throw new MonthlyConversationLimitError(e.message)
181+
}
182+
// BE service will throw ServiceQuota if code generation iteration limit is reached
183+
else if (
184+
e.code === 'ServiceQuotaExceededException' ||
185+
(e.code === 'ThrottlingException' &&
186+
e.message.includes('limit for number of iterations on a code generation'))
187+
) {
188+
throw new CodeIterationLimitError()
189+
}
178190
}
179191
throw new ToolkitError((e as Error).message, { code: 'StartCodeGenerationFailed' })
180192
}

0 commit comments

Comments
 (0)