From 6f1fdf6d8707c29d0f7d166cbaa88b1aaabfd2e4 Mon Sep 17 00:00:00 2001 From: hgw Date: Mon, 2 Oct 2023 02:11:25 +0000 Subject: [PATCH] add some more error handlers --- commands/feed.js | 12 ++++++++++-- commands/twitter.js | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/commands/feed.js b/commands/feed.js index 93460ca..3890e14 100644 --- a/commands/feed.js +++ b/commands/feed.js @@ -20,7 +20,11 @@ function errorMessage(error, code, extra) { console.log(error.code) if (code == "404") { 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" } @@ -33,7 +37,11 @@ async function fetchFeed(feedURL, n) { try { var newFeed = await parser.parseURL(feedURL); } catch (e) { - errorMessage(e, "404", feedURL); + if (e.code !== undefined) { + errorMessage(e) + } else { + errorMessage(e, "404", feedURL); + } } if (n > newFeed.items.length) { var n = newFeed.items.length; diff --git a/commands/twitter.js b/commands/twitter.js index 8608dc1..bec7834 100644 --- a/commands/twitter.js +++ b/commands/twitter.js @@ -20,7 +20,11 @@ function errorMessage(error, code, extra) { console.log(error.code) if (code == "404") { 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" } @@ -39,7 +43,11 @@ async function fetchFeed(feedURL, n) { try { var newFeed = await parser.parseURL(feedURL); } catch (e) { - errorMessage(e, "404", feedURL); + if (e.code !== undefined) { + errorMessage(e) + } else { + errorMessage(e, "404", feedURL); + } } if (n > newFeed.items.length) {