add some more error handlers

This commit is contained in:
hgw 2023-10-02 02:11:25 +00:00
parent 5f7b7c340f
commit 6f1fdf6d87
2 changed files with 20 additions and 4 deletions

View File

@ -20,7 +20,11 @@ function errorMessage(error, code, extra) {
console.log(error.code) console.log(error.code)
if (code == "404") { if (code == "404") {
var error = "[04ERROR] 404: " + extra + " not found" var error = "[04ERROR] 404: " + extra + " not found"
} else { } else if (error.code == "ECONNREFUSED") {
var error = "[04ERROR] Connection Refused"
} else if (error.code == "ERR_UNESCAPED_CHARACTERS"){
var error = "[04ERROR] Unescaped Characters"
} else {
var error = "[04ERROR] Unknown error" var error = "[04ERROR] Unknown error"
} }
@ -33,7 +37,11 @@ async function fetchFeed(feedURL, n) {
try { try {
var newFeed = await parser.parseURL(feedURL); var newFeed = await parser.parseURL(feedURL);
} catch (e) { } catch (e) {
errorMessage(e, "404", feedURL); if (e.code !== undefined) {
errorMessage(e)
} else {
errorMessage(e, "404", feedURL);
}
} }
if (n > newFeed.items.length) { if (n > newFeed.items.length) {
var n = newFeed.items.length; var n = newFeed.items.length;

View File

@ -20,7 +20,11 @@ function errorMessage(error, code, extra) {
console.log(error.code) console.log(error.code)
if (code == "404") { if (code == "404") {
var error = "[04ERROR] 404: " + extra + " not found" var error = "[04ERROR] 404: " + extra + " not found"
} else { } else if (error.code == "ECONNREFUSED") {
var error = "[04ERROR] Connection Refused"
} else if (error.code == "ERR_UNESCAPED_CHARACTERS"){
var error = "[04ERROR] Unescaped Characters"
} else {
var error = "[04ERROR] Unknown error" var error = "[04ERROR] Unknown error"
} }
@ -39,7 +43,11 @@ async function fetchFeed(feedURL, n) {
try { try {
var newFeed = await parser.parseURL(feedURL); var newFeed = await parser.parseURL(feedURL);
} catch (e) { } catch (e) {
errorMessage(e, "404", feedURL); if (e.code !== undefined) {
errorMessage(e)
} else {
errorMessage(e, "404", feedURL);
}
} }
if (n > newFeed.items.length) { if (n > newFeed.items.length) {