@@ -46,9 +46,9 @@ import kotlinx.coroutines.withContext
4646import migration.software.aws.toolkits.jetbrains.services.codewhisperer.explorer.CodeWhispererExplorerActionManager
4747import org.eclipse.lsp4j.jsonrpc.ResponseErrorException
4848import org.eclipse.lsp4j.jsonrpc.messages.Either
49- import software.amazon.awssdk.services.ssooidc.model.InvalidGrantException
5049import software.aws.toolkits.core.utils.debug
5150import software.aws.toolkits.core.utils.getLogger
51+ import software.aws.toolkits.core.utils.warn
5252import software.aws.toolkits.jetbrains.core.coroutines.getCoroutineBgContext
5353import software.aws.toolkits.jetbrains.core.credentials.AwsBearerTokenConnection
5454import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnectionManager
@@ -601,20 +601,17 @@ class QInlineCompletionProvider(private val cs: CoroutineScope) : InlineCompleti
601601 // https://github.com/aws/language-servers/blob/1f3e93024eeb22186a34f0bd560f8d552f517300/server/aws-lsp-codewhisperer/src/language-server/chat/utils.ts#L22-L23
602602 // error data is nullable
603603 if (e.responseError.data?.toString()?.contains(" E_AMAZON_Q_CONNECTION_EXPIRED" ) == true ) {
604- // kill the session if the connection is expired
605- val connection = ToolkitConnectionManager
606- .getInstance(project)
607- .activeConnectionForFeature(QConnection .getInstance()) as ? AwsBearerTokenConnection
608- val tokenProvider = connection?.let { it.getConnectionSettings().tokenProvider.delegate as ? BearerTokenProvider }
609- tokenProvider?.let {
610- // TODO: fragile
611- try {
612- it.refresh()
613- } catch (_: InvalidGrantException ) {
614- it.invalidate()
615- CodeWhispererUtil .reconnectCodeWhisperer(project)
616- }
604+ try {
605+ // kill the session if the connection is expired
606+ val connection = ToolkitConnectionManager
607+ .getInstance(project)
608+ .activeConnectionForFeature(QConnection .getInstance()) as ? AwsBearerTokenConnection
609+ connection?.let { it.getConnectionSettings().tokenProvider.delegate as ? BearerTokenProvider }
610+ ?.invalidate()
611+ } catch (e: Exception ) {
612+ LOG .warn(e) { " Failed to invalidate existing token in response to E_AMAZON_Q_CONNECTION_EXPIRED" }
617613 }
614+ CodeWhispererUtil .reconnectCodeWhisperer(project)
618615 }
619616 }
620617 return null
0 commit comments