Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/utils/generate/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,20 @@
export async function registryValidation(registryUrl?: string, registryAuth?: string, registryToken?: string) {
if (!registryUrl) { return; }
try {
const response = await fetch(registryUrl as string);
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 5000); // 5 second timeout

const response = await fetch(registryUrl as string, {

Check warning on line 15 in src/utils/generate/registry.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

This assertion is unnecessary since it does not change the type of the expression.

See more on https://sonarcloud.io/project/issues?id=asyncapi_cli&issues=AZz3F0X74qxQot7sXaBh&open=AZz3F0X74qxQot7sXaBh&pullRequest=2044
method: 'HEAD', // Use lightweight HEAD instead of GET
signal: controller.signal
});
clearTimeout(timeoutId);

if (response.status === 401 && !registryAuth && !registryToken) {
throw new Error('You Need to pass either registryAuth in username:password encoded in Base64 or need to pass registryToken');
}
} catch {
throw new Error(`Can't fetch registryURL: ${registryUrl}`);
} catch (err: any) {
// Preserve original error message
throw new Error(`Can't fetch registryURL: ${registryUrl} - ${err.message}`);
}
}
Loading