fix: on no results

This commit is contained in:
yanlong.wang 2024-05-16 17:30:47 +08:00
parent e2698b48bd
commit 322cb86f21
No known key found for this signature in database
GPG Key ID: C0A623C0BADF9F37

View File

@ -226,7 +226,11 @@ export class SearcherHost extends RPCHost {
count: 10
}, noCache);
const it = this.fetchSearchResults(customMode, r.web.results, crawlOpts, pageCacheTolerance);
if (!r.web?.results.length) {
throw new AssertionFailureError(`No search results available for query ${searchQuery}`);
}
const it = this.fetchSearchResults(customMode, r.web?.results, crawlOpts, pageCacheTolerance);
if (!ctx.req.accepts('text/plain') && ctx.req.accepts('text/event-stream')) {
const sseStream = new OutputServerEventStream();
@ -334,10 +338,13 @@ export class SearcherHost extends RPCHost {
async *fetchSearchResults(
mode: string | 'markdown' | 'html' | 'text' | 'screenshot',
searchResults: WebSearchResult[],
searchResults?: WebSearchResult[],
options?: ScrappingOptions,
pageCacheTolerance?: number
) {
if (!searchResults) {
return;
}
const urls = searchResults.map((x) => new URL(x.url));
for await (const scrapped of this.crawler.scrapMany(urls, options, pageCacheTolerance)) {
const mapped = scrapped.map((x, i) => {