From e55c7d5062b9c7a22209747e5128755715d44cf4 Mon Sep 17 00:00:00 2001 From: tamaina Date: Mon, 2 Jan 2023 18:47:25 +0000 Subject: [PATCH] fix --- packages/backend/src/core/DownloadService.ts | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/packages/backend/src/core/DownloadService.ts b/packages/backend/src/core/DownloadService.ts index 13e0066d3d..af31d6f72a 100644 --- a/packages/backend/src/core/DownloadService.ts +++ b/packages/backend/src/core/DownloadService.ts @@ -54,17 +54,13 @@ export class DownloadService { undefined, // http2: false, // default }); - - try { - await pipeline(stream.Readable.fromWeb(streaming), fs.createWriteStream(path)); - } catch (e) { - if (e instanceof Got.HTTPError) { - throw new StatusError(`${e.response.statusCode} ${e.response.statusMessage}`, e.response.statusCode, e.response.statusMessage); - } else { - throw e; - } + + if (response.body === null) { + throw new StatusError('No body', 400, 'No body'); } - + + await pipeline(stream.Readable.fromWeb(response.body), fs.createWriteStream(path)); + this.logger.succ(`Download finished: ${chalk.cyan(url)}`); }