Spaces:
Build error
Build error
fix: on no results
Browse files
backend/functions/src/cloud-functions/searcher.ts
CHANGED
|
@@ -226,7 +226,11 @@ export class SearcherHost extends RPCHost {
|
|
| 226 |
count: 10
|
| 227 |
}, noCache);
|
| 228 |
|
| 229 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
|
| 231 |
if (!ctx.req.accepts('text/plain') && ctx.req.accepts('text/event-stream')) {
|
| 232 |
const sseStream = new OutputServerEventStream();
|
|
@@ -334,10 +338,13 @@ export class SearcherHost extends RPCHost {
|
|
| 334 |
|
| 335 |
async *fetchSearchResults(
|
| 336 |
mode: string | 'markdown' | 'html' | 'text' | 'screenshot',
|
| 337 |
-
searchResults: WebSearchResult[],
|
| 338 |
options?: ScrappingOptions,
|
| 339 |
pageCacheTolerance?: number
|
| 340 |
) {
|
|
|
|
|
|
|
|
|
|
| 341 |
const urls = searchResults.map((x) => new URL(x.url));
|
| 342 |
for await (const scrapped of this.crawler.scrapMany(urls, options, pageCacheTolerance)) {
|
| 343 |
const mapped = scrapped.map((x, i) => {
|
|
|
|
| 226 |
count: 10
|
| 227 |
}, noCache);
|
| 228 |
|
| 229 |
+
if (!r.web?.results.length) {
|
| 230 |
+
throw new AssertionFailureError(`No search results available for query ${searchQuery}`);
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
const it = this.fetchSearchResults(customMode, r.web?.results, crawlOpts, pageCacheTolerance);
|
| 234 |
|
| 235 |
if (!ctx.req.accepts('text/plain') && ctx.req.accepts('text/event-stream')) {
|
| 236 |
const sseStream = new OutputServerEventStream();
|
|
|
|
| 338 |
|
| 339 |
async *fetchSearchResults(
|
| 340 |
mode: string | 'markdown' | 'html' | 'text' | 'screenshot',
|
| 341 |
+
searchResults?: WebSearchResult[],
|
| 342 |
options?: ScrappingOptions,
|
| 343 |
pageCacheTolerance?: number
|
| 344 |
) {
|
| 345 |
+
if (!searchResults) {
|
| 346 |
+
return;
|
| 347 |
+
}
|
| 348 |
const urls = searchResults.map((x) => new URL(x.url));
|
| 349 |
for await (const scrapped of this.crawler.scrapMany(urls, options, pageCacheTolerance)) {
|
| 350 |
const mapped = scrapped.map((x, i) => {
|