Skip to content

Commit

Permalink
try catch in fetch to validate hostnames
Browse files Browse the repository at this point in the history
  • Loading branch information
Sartxi committed Jun 5, 2024
1 parent 0556c84 commit 0b49fdb
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion libs/blocks/locui/loc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,20 @@ const urlParams = new URLSearchParams(window.location.search);
let resourcePath;
let previewPath;

async function validateUrl(url) {
try {
const request = await fetch(url.href);
return request;
} catch (error) {
return { ok: false, url: url.href };
}
}

async function validatedUrls(projectUrls) {
const validateUrls = [...projectUrls];
while (validateUrls.length) {
try {
const reqs = await Promise.all(validateUrls.splice(0, 49).map((url) => fetch(url.href)));
const reqs = await Promise.all(validateUrls.splice(0, 49).map(validateUrl));
setStatus('details', 'info', 'Validating Project URLs');
for (const res of reqs) {
const projectUrl = projectUrls.find((url) => url.href === res.url);
Expand Down

0 comments on commit 0b49fdb

Please sign in to comment.