I am creating an endpoint in charge of verifying that the "pages" table verifies that all the records work by checking with axios to verify that the link field works correctly or at least a status of 200. The problem with my code is that the application freezes with the first record and does not advance, also if a record contains a link that does not work the loop ends with the axios error and does not advance with the other links. If the page does not work, I delete it from the database
Code
for (var i = 0; i < pages.length; i++) {
var page = pages[i];
var name = page.name;
var link = page.link;
console.log("TEST WITH " + name);
try {
const response = await axios.get(link, {timeout: 2000});
console.log(response.status);
console.log("OK");
} catch (error) {
console.log("FAIL");
// I need link for delete in database
/*
const result = await conn.query("DELETE FROM pages WHERE link = ?", [
link,
]);
*/
}
}
I am using the latest version of NextJS
Something I forgot to mention is that the list of pages contains links to music streams
How could I achieve my goal?