Log more in vsdbg script download error case (#4383)

* Log more in vsdbg script download error case

* Better

* Make it better yet
This commit is contained in:
Brandon Waterloo [MSFT] 2024-09-12 11:58:03 -04:00 коммит произвёл GitHub
Родитель 9790ea2f24
Коммит 6f8d5995ca
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
1 изменённых файлов: 26 добавлений и 6 удалений

Просмотреть файл

@ -130,14 +130,34 @@ export interface ResponseLike {
}
export async function streamToFile(downloadUrl: string, fileName: string): Promise<void> {
const response = await fetch(downloadUrl);
const writeStream = fse.createWriteStream(fileName);
try {
const response = await fetch(downloadUrl);
for await (const chunk of response.body) {
writeStream.write(chunk);
if (!response.ok) {
throw new HttpErrorResponse(response);
}
const writeStream = fse.createWriteStream(fileName);
for await (const chunk of response.body) {
writeStream.write(chunk);
}
writeStream.close();
} catch (error) {
// Sometimes the error has a cause field, sometimes a message, sometimes maybe neither
let errorText: string;
if (typeof error === 'object') {
errorText = (error as { cause: string }).cause ?? (error as { message: string }).message ?? error.toString();
} else if (typeof error === 'string') {
errorText = error;
} else {
errorText = error.toString();
}
throw new Error(`Failed to download ${downloadUrl}: ${errorText}`);
}
writeStream.close();
}
export function basicAuthHeader(username: string, password: string): string {