From b18efa05535ee52e10795b96a8660dace9d89562 Mon Sep 17 00:00:00 2001 From: Remi Date: Sat, 9 Jan 2021 20:34:06 +0100 Subject: [PATCH] feat(techdocs): streamToString try/catch --- .../src/stages/publish/awsS3.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/techdocs-common/src/stages/publish/awsS3.ts b/packages/techdocs-common/src/stages/publish/awsS3.ts index 861a11ed93..031658bd47 100644 --- a/packages/techdocs-common/src/stages/publish/awsS3.ts +++ b/packages/techdocs-common/src/stages/publish/awsS3.ts @@ -24,13 +24,18 @@ import { PublisherBase, PublishRequest } from './types'; import fs from 'fs-extra'; import { Readable } from 'stream'; -const streamToString = (stream: Readable): Promise => - new Promise((resolve, reject) => { - const chunks: any[] = []; - stream.on('data', chunk => chunks.push(chunk)); - stream.on('error', reject); - stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8'))); - }); +const streamToString = (stream: Readable): Promise => { + try { + return new Promise((resolve, reject) => { + const chunks: any[] = []; + stream.on('data', chunk => chunks.push(chunk)); + stream.on('error', reject); + stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8'))); + }); + } catch (e) { + throw new Error(`Unable to parse the response data, ${e.message}`); + } +}; export class AwsS3Publish implements PublisherBase { static fromConfig(config: Config, logger: Logger): PublisherBase {