Skip to content

Commit ee347a9

Browse files
author
tomzu
committed
wrap request cancelled error in isUserCancelledError
1 parent fbc0de0 commit ee347a9

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

packages/core/src/shared/errors.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { CodeWhispererStreamingServiceException } from '@amzn/codewhisperer-stre
1616
import { driveLetterRegex } from './utilities/pathUtils'
1717
import { getLogger } from './logger/logger'
1818
import { crashMonitoringDirName } from './constants'
19+
import { RequestCancelledError } from './request'
1920

2021
let _username = 'unknown-user'
2122
let _isAutomation = false
@@ -618,7 +619,11 @@ function hasTime(error: Error): error is typeof error & { time: Date } {
618619
}
619620

620621
export function isUserCancelledError(error: unknown): boolean {
621-
return CancellationError.isUserCancelled(error) || (error instanceof ToolkitError && error.cancelled)
622+
return (
623+
CancellationError.isUserCancelled(error) ||
624+
(error instanceof ToolkitError && error.cancelled) ||
625+
error instanceof RequestCancelledError
626+
)
622627
}
623628

624629
/**

packages/core/src/shared/lsp/lspResolver.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ import { createHash } from '../crypto'
1515
import { lspSetupStage, StageResolver, tryStageResolvers } from './utils/setupStage'
1616
import { HttpResourceFetcher } from '../resourcefetcher/httpResourceFetcher'
1717
import { showMessageWithCancel } from '../../shared/utilities/messages'
18-
import { CancellationError, Timeout } from '../utilities/timeoutUtils'
19-
import { RequestCancelledError } from '../request'
18+
import { Timeout } from '../utilities/timeoutUtils'
2019

2120
// max timeout for downloading remote LSP assets progress, the lowest possible is 3000, bounded by httpResourceFetcher's waitUntil
2221
const remoteDownloadTimeout = 5000
@@ -114,11 +113,6 @@ export class LanguageServerResolver {
114113
} else {
115114
throw new ToolkitError('Failed to download server from remote', { code: 'RemoteDownloadFailed' })
116115
}
117-
} catch (err) {
118-
if (err instanceof RequestCancelledError) {
119-
throw new CancellationError('user')
120-
}
121-
throw err
122116
} finally {
123117
timeout.dispose()
124118
}

packages/core/src/shared/resourcefetcher/httpResourceFetcher.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { VSCODE_EXTENSION_ID } from '../extensions'
77
import { getLogger, Logger } from '../logger/logger'
88
import { ResourceFetcher } from './resourcefetcher'
99
import { Timeout, CancelEvent, waitUntil } from '../utilities/timeoutUtils'
10-
import request, { RequestCancelledError, RequestError } from '../request'
10+
import request, { RequestError } from '../request'
11+
import { isUserCancelledError } from '../errors'
1112

1213
type RequestHeaders = { eTag?: string; gZip?: boolean }
1314

@@ -120,8 +121,8 @@ export class HttpResourceFetcher implements ResourceFetcher<Response> {
120121
interval: 100,
121122
backoff: 2,
122123
retryOnFail: (error: Error) => {
123-
// retry unless we got an user cancellation error
124-
return !(error instanceof RequestCancelledError)
124+
// Retry unless the user intentionally canceled the operation.
125+
return !isUserCancelledError(error)
125126
},
126127
}
127128
)

0 commit comments

Comments
 (0)