Skip to content

Commit a9dbe7a

Browse files
Merge staging into feature/lambda-get-started
2 parents 3e2b9bb + d44331c commit a9dbe7a

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)