mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2026-03-13 16:16:46 +00:00
Add timeout and validation to SearXNG search
This commit is contained in:
@@ -38,11 +38,30 @@ export const searchSearxng = async (
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await fetch(url);
|
const controller = new AbortController();
|
||||||
const data = await res.json();
|
const timeoutId = setTimeout(() => controller.abort(), 10000);
|
||||||
|
|
||||||
const results: SearxngSearchResult[] = data.results;
|
try {
|
||||||
const suggestions: string[] = data.suggestions;
|
const res = await fetch(url, {
|
||||||
|
signal: controller.signal,
|
||||||
|
});
|
||||||
|
|
||||||
return { results, suggestions };
|
if (!res.ok) {
|
||||||
|
throw new Error(`SearXNG error: ${res.statusText}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await res.json();
|
||||||
|
|
||||||
|
const results: SearxngSearchResult[] = data.results;
|
||||||
|
const suggestions: string[] = data.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