Skip to content

Commit 19d8099

Browse files
committed
Pull error messages as constants
1 parent 51d65e1 commit 19d8099

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { ServiceOptions } from '../../shared/awsClientBuilder'
1010
import globals from '../../shared/extensionGlobals'
1111
import { getLogger } from '../../shared/logger'
1212
import * as FeatureDevProxyClient from './featuredevproxyclient'
13-
import { featureName } from '../constants'
13+
import { featureName, startTaskAssisLimitReachedMessage } from '../constants'
1414
import { CodeReference } from '../../amazonq/webview/ui/connector'
1515
import {
1616
ApiError,
@@ -185,10 +185,7 @@ export class FeatureDevClient {
185185
)
186186
if (isAwsError(e)) {
187187
// API Front-end will throw Throttling if conversation limit is reached. API Front-end monitors StartCodeGeneration for throttling
188-
if (
189-
e.code === 'ThrottlingException' &&
190-
e.message.includes('StartTaskAssistCodeGeneration reached for this month.')
191-
) {
188+
if (e.code === 'ThrottlingException' && e.message.includes(startTaskAssisLimitReachedMessage)) {
192189
throw new MonthlyConversationLimitError(e.message)
193190
}
194191
// BE service will throw ServiceQuota if code generation iteration limit is reached

packages/core/src/amazonqFeatureDev/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ export const generateDevFilePrompt =
2121
export const maxRepoSizeBytes = 200 * 1024 * 1024
2222

2323
export const startCodeGenClientErrorMessages = ['Improperly formed request', 'Resource not found']
24+
export const startTaskAssisLimitReachedMessage = 'StartTaskAssistCodeGeneration reached for this month.'
2425
export const clientErrorMessages = [
25-
'StartTaskAssistCodeGeneration reached for this month.',
2626
'The folder you chose did not contain any source files in a supported language. Choose another folder and try again.',
2727
]
2828

packages/core/src/amazonqFeatureDev/controllers/chat/controller.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
featureName,
3636
generateDevFilePrompt,
3737
startCodeGenClientErrorMessages,
38+
startTaskAssisLimitReachedMessage,
3839
} from '../../constants'
3940
import { DeletedFileInfo, DevPhase, MetricDataOperationName, MetricDataResult, type NewFileInfo } from '../../types'
4041
import { AuthUtil } from '../../../codewhisperer/util/authUtil'
@@ -571,7 +572,8 @@ export class FeatureDevController {
571572
if (
572573
(err.code === 'StartCodeGenerationFailed' &&
573574
startCodeGenClientErrorMessages.some((msg) => err.message.includes(msg))) ||
574-
clientErrorMessages.some((msg) => err.message.includes(msg))
575+
clientErrorMessages.some((msg) => err.message.includes(msg)) ||
576+
err.message.includes(startTaskAssisLimitReachedMessage)
575577
) {
576578
result = MetricDataResult.Error
577579
} else {

packages/core/src/test/amazonqFeatureDev/controllers/chat/controller.test.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,14 @@ import { CodeGenState, PrepareCodeGenState } from '../../../../amazonqFeatureDev
3939
import { FeatureDevClient } from '../../../../amazonqFeatureDev/client/featureDev'
4040
import { createAmazonQUri } from '../../../../amazonq/commons/diff'
4141
import { AuthUtil } from '../../../../codewhisperer'
42-
import { featureDevScheme, featureName, messageWithConversationId } from '../../../../amazonqFeatureDev'
42+
import {
43+
featureDevScheme,
44+
featureName,
45+
messageWithConversationId,
46+
clientErrorMessages,
47+
startCodeGenClientErrorMessages,
48+
startTaskAssisLimitReachedMessage,
49+
} from '../../../../amazonqFeatureDev'
4350
import { i18n } from '../../../../shared/i18n-helper'
4451
import { FollowUpTypes } from '../../../../amazonq/commons/types'
4552
import { ToolkitError } from '../../../../shared'
@@ -481,18 +488,13 @@ describe('Controller', () => {
481488
}
482489
if (
483490
error.code === 'StartCodeGenerationFailed' &&
484-
(error.message.includes('Improperly formed request') ||
485-
error.message.includes('Resource not found'))
491+
startCodeGenClientErrorMessages.some((msg: string) => error.message.includes(msg))
486492
) {
487493
return MetricDataResult.Error
488494
}
489-
if (error.message.includes('StartTaskAssistCodeGeneration reached for this month.')) {
490-
return MetricDataResult.Error
491-
}
492495
if (
493-
error.message.includes(
494-
'The folder you chose did not contain any source files in a supported language. Choose another folder and try again.'
495-
)
496+
clientErrorMessages.some((msg: string) => error.message.includes(msg)) ||
497+
error.message.includes(startTaskAssisLimitReachedMessage) // Include this check
496498
) {
497499
return MetricDataResult.Error
498500
}

0 commit comments

Comments
 (0)