From f79af457fcf001f6b522a19661c5a385ad007469 Mon Sep 17 00:00:00 2001 From: Pedro Ramos Date: Fri, 12 Apr 2024 15:50:18 +0200 Subject: [PATCH] Refactor some error cases --- scripts/fetch-asyncapi-example.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/scripts/fetch-asyncapi-example.js b/scripts/fetch-asyncapi-example.js index 0f60108ff5e..471954d71ab 100644 --- a/scripts/fetch-asyncapi-example.js +++ b/scripts/fetch-asyncapi-example.js @@ -29,7 +29,9 @@ const fetchAsyncAPIExamplesFromExternalURL = () => { .on('close', () => { console.log('Fetched ZIP file'); resolve(); - }).on('error', reject); + }).on('error', (error) => { + reject(new Error(`Error in fetching ZIP file ${error.message}`)); + }); }); }; @@ -51,10 +53,10 @@ const unzipAsyncAPIExamples = async () => { entry.autodrain(); } }).on('close', () => { - console.log('Unzipped all examples from zip'); + console.log('Unzipped all examples from ZIP'); resolve(); - }).on('error', () => { - reject(); + }).on('error', (error) => { + reject(new Error(`Error in unzipping from ZIP: ${error.message}`)); }); }); }; @@ -65,11 +67,11 @@ const buildCLIListFromExamples = async () => { const buildExampleList = examples.map(async example => { const examplePath = path.join(EXAMPLE_DIRECTORY, example); - const exampleContent = fs.readFileSync(examplePath, { encoding: 'utf-8'}); + const exampleContent = fs.readFileSync(examplePath, { encoding: 'utf-8' }); try { const { document } = await parser.parse(exampleContent); - // Failed for somereason to parse this spec file (document is undefined), ignore for now + // Failed for some reason to parse this spec file (document is undefined), ignore for now if (!document) { return; } @@ -100,7 +102,7 @@ const listAllProtocolsForFile = (document) => { return servers.all().map(server => server.protocol()).join(','); }; -const tidyup = async () => { +const tidyUp = async () => { fs.unlinkSync(TEMP_ZIP_NAME); }; @@ -108,5 +110,5 @@ const tidyup = async () => { await fetchAsyncAPIExamplesFromExternalURL(); await unzipAsyncAPIExamples(); await buildCLIListFromExamples(); - await tidyup(); + await tidyUp(); })();