@@ -14,7 +14,7 @@ import {
14
14
type SessionStateConfig ,
15
15
UpdateFilesPathsParams ,
16
16
} from '../../amazonq/commons/types'
17
- import { ConversationIdNotFoundError } from '../errors'
17
+ import { ContentLengthError , ConversationIdNotFoundError } from '../errors'
18
18
import { featureDevChat , referenceLogText , featureDevScheme } from '../constants'
19
19
import fs from '../../shared/fs/fs'
20
20
import { FeatureDevClient } from '../client/featureDev'
@@ -33,6 +33,7 @@ import { UpdateAnswerMessage } from '../../amazonq/commons/connector/connectorMe
33
33
import { FollowUpTypes } from '../../amazonq/commons/types'
34
34
import { SessionConfig } from '../../amazonq/commons/session/sessionConfigFactory'
35
35
import { Messenger } from '../../amazonq/commons/connector/baseMessenger'
36
+ import { ContentLengthError as CommonAmazonQContentLengthError } from '../../amazonq/errors'
36
37
export class Session {
37
38
private _state ?: SessionState | Omit < SessionState , 'uploadId' >
38
39
private task : string = ''
@@ -137,25 +138,33 @@ export class Session {
137
138
}
138
139
139
140
private async nextInteraction ( msg : string ) {
140
- const resp = await this . state . interact ( {
141
- task : this . task ,
142
- msg,
143
- fs : this . config . fs ,
144
- messenger : this . messenger ,
145
- telemetry : this . telemetry ,
146
- tokenSource : this . state . tokenSource ,
147
- uploadHistory : this . state . uploadHistory ,
148
- } )
141
+ try {
142
+ const resp = await this . state . interact ( {
143
+ task : this . task ,
144
+ msg,
145
+ fs : this . config . fs ,
146
+ messenger : this . messenger ,
147
+ telemetry : this . telemetry ,
148
+ tokenSource : this . state . tokenSource ,
149
+ uploadHistory : this . state . uploadHistory ,
150
+ } )
149
151
150
- if ( resp . nextState ) {
151
- if ( ! this . state ?. tokenSource ?. token . isCancellationRequested ) {
152
- this . state ?. tokenSource ?. cancel ( )
152
+ if ( resp . nextState ) {
153
+ if ( ! this . state ?. tokenSource ?. token . isCancellationRequested ) {
154
+ this . state ?. tokenSource ?. cancel ( )
155
+ }
156
+ // Move to the next state
157
+ this . _state = resp . nextState
153
158
}
154
- // Move to the next state
155
- this . _state = resp . nextState
156
- }
157
159
158
- return resp . interaction
160
+ return resp . interaction
161
+ } catch ( e ) {
162
+ if ( e instanceof CommonAmazonQContentLengthError ) {
163
+ getLogger ( ) . debug ( `Content length validation failed: ${ e . message } ` )
164
+ throw new ContentLengthError ( )
165
+ }
166
+ throw e
167
+ }
159
168
}
160
169
161
170
public async updateFilesPaths ( params : UpdateFilesPathsParams ) {
0 commit comments