Skip to content

Commit cd82930

Browse files
committed
addressing review comments
1 parent 8b01dd3 commit cd82930

4 files changed

Lines changed: 29 additions & 12 deletions

File tree

extensions/mssql/src/http/httpClientCore.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Readable } from "stream";
1212
import { ILogger } from "../models/interfaces";
1313

1414
const UnableToGetProxyAgentOptionsMessage = "Unable to read proxy agent options to get tenants.";
15+
const DefaultRequestTimeoutMs = 20000; // 20 seconds
1516

1617
export interface IHttpClientMessages {
1718
missingProtocolWarning(proxy: string): string;
@@ -25,6 +26,7 @@ export interface IHttpClientDependencies {
2526
parseUriScheme?: (value: string) => string | undefined;
2627
showWarningMessage?: (message: string) => void;
2728
getErrorMessage?: (error: unknown) => string;
29+
getRequestTimeout?: () => number;
2830
messages?: IHttpClientMessages;
2931
}
3032

@@ -168,12 +170,12 @@ export class HttpClientCore {
168170
: new URL(proxy).protocol;
169171

170172
if (!scheme) {
171-
message = `Proxy settings found, but without a protocol (e.g. http://): '${proxy}'. You may encounter connection issues while using the MSSQL extension.`;
173+
message = `Proxy settings found, but without a protocol (e.g. http://): '${proxy}'. You may encounter connection issues while using this extension.`;
172174
localizedMessage = this.dependencies.messages?.missingProtocolWarning(proxy);
173175
}
174176
} catch (err) {
175177
const errorMessage = this.getErrorMessage(err);
176-
message = `Proxy settings found, but encountered an error while parsing the URL: '${proxy}'. You may encounter connection issues while using the MSSQL extension. Error: ${errorMessage}`;
178+
message = `Proxy settings found, but encountered an error while parsing the URL: '${proxy}'. You may encounter connection issues while using this extension. Error: ${errorMessage}`;
177179
localizedMessage = this.dependencies.messages?.unparseableWarning(proxy, errorMessage);
178180
}
179181

@@ -225,6 +227,7 @@ export class HttpClientCore {
225227
const config: AxiosRequestConfig = {
226228
headers,
227229
validateStatus: () => true, // Never throw
230+
timeout: this.dependencies.getRequestTimeout?.() ?? DefaultRequestTimeoutMs,
228231
};
229232

230233
const proxy = this.loadProxyConfig();
@@ -410,7 +413,11 @@ export class HttpClientCore {
410413

411414
return {
412415
host: proxyEndpoint.hostname,
413-
port: Number(proxyEndpoint.port),
416+
port: proxyEndpoint.port
417+
? Number(proxyEndpoint.port)
418+
: proxyEndpoint.protocol === "https:"
419+
? 443
420+
: 80,
414421
auth,
415422
rejectUnauthorized: typeof strictSSL === "boolean",
416423
};

extensions/sql-database-projects/src/controllers/mainController.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import * as constants from "../common/constants";
2121
import { SqlDatabaseProjectProvider } from "../projectProvider/projectProvider";
2222
import { GenerateProjectFromOpenApiSpecOptions, ItemType } from "sqldbproj";
2323
import { FileNode } from "../models/tree/fileFolderTreeItem";
24+
import { HttpClient } from "../http/httpClient";
2425

2526
/**
2627
* The main controller class that initializes the extension
@@ -61,6 +62,9 @@ export default class MainController implements vscode.Disposable {
6162
.update(DotnetInstallLocationKey, oldNetCoreInstallSetting, true);
6263
}
6364

65+
// Warn about invalid proxy settings early during activation
66+
new HttpClient().warnOnInvalidProxySettings();
67+
6468
await this.initializeDatabaseProjects();
6569
return new SqlDatabaseProjectProvider(this.projectsController);
6670
}

extensions/sql-database-projects/src/http/httpClient.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ import * as fs from "fs";
88
import {
99
HttpClientCore,
1010
IHttpClientDependencies,
11-
ILogger,
1211
HttpDownloadError,
1312
IDownloadFileOptions,
1413
IDownloadFileResult,
1514
} from "./httpClientCore";
15+
import { ILogger } from "../common/logger";
1616
import * as constants from "../common/constants";
17+
import { getErrorMessage } from "../common/utils";
1718

1819
export class HttpClient extends HttpClientCore {
1920
constructor(logger?: ILogger) {
@@ -27,6 +28,7 @@ export class HttpClient extends HttpClientCore {
2728
showWarningMessage: (message: string) => {
2829
void vscode.window.showWarningMessage(message);
2930
},
31+
getErrorMessage,
3032
// Provide a messages implementation so that HttpClientCore can surface
3133
// proxy warnings via showWarningMessage. Without this, warnOnInvalidProxySettings
3234
// would silently skip the showWarningMessage call even though it is wired up above.
@@ -82,8 +84,7 @@ export class HttpClient extends HttpClientCore {
8284
try {
8385
result = await this.downloadFile(downloadUrl, fd, options);
8486
} catch (e) {
85-
const message = e instanceof Error ? e.message : String(e);
86-
outputChannel?.appendLine(`${constants.downloadError}: ${message}`);
87+
outputChannel?.appendLine(`${constants.downloadError}: ${getErrorMessage(e)}`);
8788
throw e;
8889
} finally {
8990
fs.closeSync(fd);

extensions/sql-database-projects/src/http/httpClientCore.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ import axios, { AxiosRequestConfig, AxiosResponse, RawAxiosResponseHeaders } fro
1414
import { Readable } from "stream";
1515
import { ILogger } from "../common/logger";
1616

17-
export type { ILogger };
18-
19-
const UnableToGetProxyAgentOptionsMessage = "Unable to read proxy agent options to get tenants.";
17+
const UnableToGetProxyAgentOptionsMessage = "Unable to read proxy agent options.";
18+
const DefaultRequestTimeoutMs = 20000; // 20 seconds
2019

2120
export interface IHttpClientMessages {
2221
missingProtocolWarning(proxy: string): string;
@@ -30,6 +29,7 @@ export interface IHttpClientDependencies {
3029
parseUriScheme?: (value: string) => string | undefined;
3130
showWarningMessage?: (message: string) => void;
3231
getErrorMessage?: (error: unknown) => string;
32+
getRequestTimeout?: () => number;
3333
messages?: IHttpClientMessages;
3434
}
3535

@@ -179,12 +179,12 @@ export class HttpClientCore {
179179
: new URL(proxy).protocol;
180180

181181
if (!scheme) {
182-
message = `Proxy settings found, but without a protocol (e.g. http://): '${proxy}'. You may encounter connection issues while using the MSSQL extension.`;
182+
message = `Proxy settings found, but without a protocol (e.g. http://): '${proxy}'. You may encounter connection issues while using this extension.`;
183183
localizedMessage = this.dependencies.messages?.missingProtocolWarning(proxy);
184184
}
185185
} catch (err) {
186186
const errorMessage = this.getErrorMessage(err);
187-
message = `Proxy settings found, but encountered an error while parsing the URL: '${proxy}'. You may encounter connection issues while using the MSSQL extension. Error: ${errorMessage}`;
187+
message = `Proxy settings found, but encountered an error while parsing the URL: '${proxy}'. You may encounter connection issues while using this extension. Error: ${errorMessage}`;
188188
localizedMessage = this.dependencies.messages?.unparseableWarning(proxy, errorMessage);
189189
}
190190

@@ -236,6 +236,7 @@ export class HttpClientCore {
236236
const config: AxiosRequestConfig = {
237237
headers,
238238
validateStatus: () => true, // Never throw
239+
timeout: this.dependencies.getRequestTimeout?.() ?? DefaultRequestTimeoutMs,
239240
};
240241

241242
const proxy = this.loadProxyConfig();
@@ -427,7 +428,11 @@ export class HttpClientCore {
427428

428429
return {
429430
host: proxyEndpoint.hostname,
430-
port: Number(proxyEndpoint.port),
431+
port: proxyEndpoint.port
432+
? Number(proxyEndpoint.port)
433+
: proxyEndpoint.protocol === "https:"
434+
? 443
435+
: 80,
431436
auth,
432437
// Default to rejecting unauthorized certs unless the user explicitly disables strict SSL.
433438
rejectUnauthorized: strictSSL !== false,

0 commit comments

Comments
 (0)