From 852dba83458c57ce5fef65fbd98a7b6ae8ca1e97 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Thu, 16 Oct 2025 19:03:13 -0700 Subject: [PATCH] Update URLContextProvider.ts --- core/context/providers/URLContextProvider.ts | 31 +++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/core/context/providers/URLContextProvider.ts b/core/context/providers/URLContextProvider.ts index 3e025d08c..bfc2c29a1 100644 --- a/core/context/providers/URLContextProvider.ts +++ b/core/context/providers/URLContextProvider.ts @@ -37,6 +37,23 @@ export async function getUrlContextItems( const url = new URL(query); const icon = await fetchFavicon(url); const resp = await fetchFn(url); + + // Check if the response is not OK + if (!resp.ok) { + return [ + { + icon, + description: url.toString(), + content: `Failed to fetch URL: HTTP ${resp.status} ${resp.statusText}`, + name: `HTTP ${resp.status}`, + uri: { + type: "url", + value: url.toString(), + }, + }, + ]; + } + const html = await resp.text(); const dom = new JSDOM(html); @@ -66,6 +83,18 @@ export async function getUrlContextItems( ]; } catch (e) { console.log(e); - return []; + const errorMessage = e instanceof Error ? e.message : "Unknown error"; + + return [ + { + description: `Error fetching ${query}`, + content: `Failed to fetch URL: ${errorMessage}`, + name: "Fetch Error", + uri: { + type: "url", + value: query, + }, + }, + ]; } }