Skip to content

Commit 6e101bc

Browse files
committed
fix: use type-safe error message access in URL mention error handling
Fixes inconsistent error handling where errorMessage was safely extracted but error.message was still accessed directly in conditionals, which could cause runtime errors if error.message was undefined.
1 parent 3a3975c commit 6e101bc

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/core/mentions/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ export async function parseMentions(
102102

103103
// Provide more helpful error messages based on error type
104104
let errorMessage = error instanceof Error ? error.message : String(error)
105-
if (error.message.includes("timeout")) {
105+
if (errorMessage.includes("timeout")) {
106106
errorMessage = `The website took too long to load (timeout). This could be due to a slow connection, heavy website, or the site being temporarily unavailable. You can try again later or check if the URL is correct.`
107-
} else if (error.message.includes("net::ERR_NAME_NOT_RESOLVED")) {
107+
} else if (errorMessage.includes("net::ERR_NAME_NOT_RESOLVED")) {
108108
errorMessage = `The website address could not be found. Please check if the URL is correct and try again.`
109-
} else if (error.message.includes("net::ERR_INTERNET_DISCONNECTED")) {
109+
} else if (errorMessage.includes("net::ERR_INTERNET_DISCONNECTED")) {
110110
errorMessage = `No internet connection. Please check your network connection and try again.`
111-
} else if (error.message.includes("403") || error.message.includes("Forbidden")) {
111+
} else if (errorMessage.includes("403") || errorMessage.includes("Forbidden")) {
112112
errorMessage = `Access to this website is forbidden. The site may block automated access or require authentication.`
113-
} else if (error.message.includes("404") || error.message.includes("Not Found")) {
113+
} else if (errorMessage.includes("404") || errorMessage.includes("Not Found")) {
114114
errorMessage = `The page was not found. Please check if the URL is correct.`
115115
}
116116

0 commit comments

Comments
 (0)