mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2026-03-13 08:06:47 +00:00
Merge pull request #1015 from joaquinescalante23/fix/search-resilience-and-timeouts
feat: improve search resilience with timeouts and widget error handling
This commit is contained in:
@@ -19,6 +19,9 @@ class APISearchAgent {
|
|||||||
chatHistory: input.chatHistory,
|
chatHistory: input.chatHistory,
|
||||||
followUp: input.followUp,
|
followUp: input.followUp,
|
||||||
llm: input.config.llm,
|
llm: input.config.llm,
|
||||||
|
}).catch((err) => {
|
||||||
|
console.error(`Error executing widgets: ${err}`);
|
||||||
|
return [];
|
||||||
});
|
});
|
||||||
|
|
||||||
let searchPromise: Promise<ResearcherOutput> | null = null;
|
let searchPromise: Promise<ResearcherOutput> | null = null;
|
||||||
|
|||||||
@@ -38,11 +38,30 @@ export const searchSearxng = async (
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await fetch(url);
|
const controller = new AbortController();
|
||||||
|
const timeoutId = setTimeout(() => controller.abort(), 10000);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch(url, {
|
||||||
|
signal: controller.signal,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error(`SearXNG error: ${res.statusText}`);
|
||||||
|
}
|
||||||
|
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
|
||||||
const results: SearxngSearchResult[] = data.results;
|
const results: SearxngSearchResult[] = data.results;
|
||||||
const suggestions: string[] = data.suggestions;
|
const suggestions: string[] = data.suggestions;
|
||||||
|
|
||||||
return { results, suggestions };
|
return { results, suggestions };
|
||||||
|
} catch (err: any) {
|
||||||
|
if (err.name === 'AbortError') {
|
||||||
|
throw new Error('SearXNG search timed out');
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
} finally {
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user