Skip to content

Commit 23f057e

Browse files
committed
fix(MongoBinaryDownload): unify how the downloadUrl is represented
1 parent ada4f2a commit 23f057e

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

packages/mongodb-memory-server-core/src/util/MongoBinaryDownload.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export class MongoBinaryDownload {
205205
return downloadLocation;
206206
}
207207

208-
this._downloadingUrl = downloadUrl;
208+
this.assignDownloadingURL(urlObject);
209209

210210
const downloadedFile = await this.httpDownload(
211211
urlObject,
@@ -358,11 +358,12 @@ export class MongoBinaryDownload {
358358
tempDownloadLocation: string
359359
): Promise<string> {
360360
log('httpDownload');
361+
const downloadUrl = this.assignDownloadingURL(url);
361362

362363
return new Promise((resolve, reject) => {
363364
const fileStream = createWriteStream(tempDownloadLocation);
364365

365-
log(`httpDownload: trying to download https://${url.hostname}${url.pathname}`);
366+
log(`httpDownload: trying to download ${downloadUrl}`);
366367
https
367368
.get(url, httpOptions, (response) => {
368369
if (response.statusCode != 200) {
@@ -371,7 +372,7 @@ export class MongoBinaryDownload {
371372
new Error(
372373
"Status Code is 403 (MongoDB's 404)\n" +
373374
"This means that the requested version-platform combination doesn't exist\n" +
374-
` Used Url: "https://${url.hostname}${url.pathname}"\n` +
375+
` Used Url: "${downloadUrl}"\n` +
375376
"Try to use different version 'new MongoMemoryServer({ binary: { version: 'X.Y.Z' } })'\n" +
376377
'List of available versions can be found here:\n' +
377378
' https://www.mongodb.org/dl/linux for Linux\n' +
@@ -404,7 +405,6 @@ export class MongoBinaryDownload {
404405
this.dlProgress.current < this.dlProgress.length &&
405406
!httpOptions.path?.endsWith('.md5')
406407
) {
407-
const downloadUrl = this._downloadingUrl || `https://${url.hostname}${url.pathname}`;
408408
reject(
409409
new Error(
410410
`Too small (${this.dlProgress.current} bytes) mongod binary downloaded from ${downloadUrl}`
@@ -429,7 +429,7 @@ export class MongoBinaryDownload {
429429
})
430430
.on('error', (e: Error) => {
431431
// log it without having debug enabled
432-
console.error(`Couldnt download ${httpOptions.path}!`, e.message);
432+
console.error(`Couldnt download "${downloadUrl}"!`, e.message);
433433
reject(e);
434434
});
435435
});
@@ -464,6 +464,15 @@ export class MongoBinaryDownload {
464464
console.log(message);
465465
}
466466
}
467+
468+
/**
469+
* Helper function to de-duplicate assigning "_downloadingUrl"
470+
*/
471+
assignDownloadingURL(url: URL): string {
472+
this._downloadingUrl = url.href;
473+
474+
return this._downloadingUrl;
475+
}
467476
}
468477

469478
export default MongoBinaryDownload;

0 commit comments

Comments
 (0)