major bug fixed + error handling

This commit is contained in:
Daniel
2023-06-27 03:05:12 +03:30
parent f1bd48be83
commit 92f6ee3942
10 changed files with 122 additions and 86 deletions
+10 -6
View File
@@ -1,9 +1,13 @@
export default async function getTitle(url: string) {
const response = await fetch(url);
const text = await response.text();
try {
const response = await fetch(url);
const text = await response.text();
// regular expression to find the <title> tag
let match = text.match(/<title.*>([^<]*)<\/title>/);
if (match) return match[1] + " [AUTO GENERATED]";
else return "";
// regular expression to find the <title> tag
let match = text.match(/<title.*>([^<]*)<\/title>/);
if (match) return match[1] + " [AUTO GENERATED]";
else return "";
} catch (err) {
console.log(err);
}
}