Skip to content

Commit

Permalink
Refactor some error cases
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-rr committed Apr 12, 2024
1 parent 819b0e7 commit f79af45
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions scripts/fetch-asyncapi-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`));
});
});
};

Expand All @@ -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}`));
});
});
};
Expand All @@ -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;
}
Expand Down Expand Up @@ -100,13 +102,13 @@ const listAllProtocolsForFile = (document) => {
return servers.all().map(server => server.protocol()).join(',');
};

const tidyup = async () => {
const tidyUp = async () => {
fs.unlinkSync(TEMP_ZIP_NAME);
};

(async () => {
await fetchAsyncAPIExamplesFromExternalURL();
await unzipAsyncAPIExamples();
await buildCLIListFromExamples();
await tidyup();
await tidyUp();
})();

0 comments on commit f79af45

Please sign in to comment.