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
Prev Previous commit
Merge branch 'master' into refactor/fetch-asyncapi-example
peter-rr authored May 17, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 7b89111fe528ffd7f827c413b195debf9670f118
32 changes: 22 additions & 10 deletions scripts/fetch-asyncapi-example.js
Original file line number Diff line number Diff line change
@@ -23,16 +23,28 @@ const EXAMPLE_DIRECTORY = path.join(__dirname, '../assets/examples');
const TEMP_ZIP_NAME = 'spec-examples.zip';

const fetchAsyncAPIExamplesFromExternalURL = () => {
return new Promise((resolve, reject) => {
request(SPEC_EXAMPLES_ZIP_URL)
.pipe(fs.createWriteStream(TEMP_ZIP_NAME))
.on('close', () => {
console.log('Fetched ZIP file');
resolve();
}).on('error', (error) => {
reject(new Error(`Error in fetching ZIP file ${error.message}`));
});
});
try {
return new Promise((resolve, reject) => {
fetch(SPEC_EXAMPLES_ZIP_URL)
.then((res) => {
if (res.status !== 200) {
reject(new Error(`Failed to fetch examples from ${SPEC_EXAMPLES_ZIP_URL}`));
}
const file = fs.createWriteStream(TEMP_ZIP_NAME);
res.body.pipe(file);
file.on('close', () => {
console.log('Fetched ZIP file');
file.close();
resolve();
}).on('error', (err) => {
reject(err);
});
})
.catch(reject);
});
} catch (error) {
console.error(error);
}
};

const unzipAsyncAPIExamples = async () => {
You are viewing a condensed version of this merge commit. You can view the full changes here.