Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: improve error cases in 'scripts/fetch-asyncapi-example.js' #1364

Merged
14 changes: 7 additions & 7 deletions scripts/fetch-asyncapi-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,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 @@ -79,11 +79,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 @@ -114,13 +114,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();
})();
Loading