Skip to content

Commit d44331c

Browse files
auth: ignore vscode proxy errors on token refresh #5198
We were seeing an error in `aws_refreshCredentials` metric. This error was networking related when the user has setup a proxy in vscode, but they were not connected to it. Maybe they didn't connect to VPN. We typically catch network errors during the SSO token refresh process so that the session does not become invalidated on it. We do not catch all errors, but will add them in incrementally as we see them in telemetry. This proxy error was not caught and caused sessions to become invalidated prematurely. Solution Treat this VSCode Proxy Error as a network error so that we ignore it during token refresh Signed-off-by: Nikolas Komonen <[email protected]>
1 parent 7d6b79f commit d44331c

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

packages/core/src/shared/errors.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,10 @@ export class PermissionsError extends ToolkitError {
565565
}
566566

567567
export function isNetworkError(err?: unknown): err is Error & { code: string } {
568+
if (isVSCodeProxyError(err)) {
569+
return true
570+
}
571+
568572
if (!hasCode(err)) {
569573
return false
570574
}
@@ -584,3 +588,17 @@ export function isNetworkError(err?: unknown): err is Error & { code: string } {
584588
'EADDRNOTAVAIL', // port not available/allowed?
585589
].includes(err.code)
586590
}
591+
592+
/**
593+
* This error occurs on a network call if the user has set up a proxy in the
594+
* VS Code settings but the proxy is not reachable.
595+
*
596+
* Setting ID: http.proxy
597+
*/
598+
function isVSCodeProxyError(err?: unknown): boolean {
599+
if (!(err instanceof Error)) {
600+
return false
601+
}
602+
603+
return err.name === 'Error' && err.message.startsWith('Failed to establish a socket connection to proxies')
604+
}

packages/core/src/test/shared/errors.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
getErrorMsg,
1212
getTelemetryReason,
1313
getTelemetryResult,
14+
isNetworkError,
1415
resolveErrorMessageToDisplay,
1516
ToolkitError,
1617
} from '../../shared/errors'
@@ -416,4 +417,17 @@ describe('util', function () {
416417
;(err as any).error_description = 'aws error desc 1'
417418
assert.deepStrictEqual(getErrorMsg(err), 'aws error desc 1')
418419
})
420+
421+
it('isNetworkError()', function () {
422+
assert.deepStrictEqual(
423+
isNetworkError(new Error('Failed to establish a socket connection to proxies BLAH BLAH BLAH')),
424+
true,
425+
'Did not return "true" on a VS Code Proxy error'
426+
)
427+
assert.deepStrictEqual(
428+
isNetworkError(new Error('I am NOT a network error')),
429+
false,
430+
'Incorrectly indicated as network error'
431+
)
432+
})
419433
})

0 commit comments

Comments
 (0)