Spaces:
Build error
Build error
fix: logging for search error
Browse files
backend/functions/src/cloud-functions/searcher.ts
CHANGED
|
@@ -451,20 +451,31 @@ ${this.content}
|
|
| 451 |
}
|
| 452 |
}
|
| 453 |
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 467 |
|
| 468 |
-
return r;
|
| 469 |
}
|
| 470 |
}
|
|
|
|
| 451 |
}
|
| 452 |
}
|
| 453 |
|
| 454 |
+
try {
|
| 455 |
+
const r = await this.braveSearchService.webSearch(query);
|
| 456 |
+
|
| 457 |
+
const nowDate = new Date();
|
| 458 |
+
const record = SearchResult.from({
|
| 459 |
+
query,
|
| 460 |
+
queryDigest,
|
| 461 |
+
response: r,
|
| 462 |
+
createdAt: nowDate,
|
| 463 |
+
expireAt: new Date(nowDate.valueOf() + this.cacheRetentionMs)
|
| 464 |
+
});
|
| 465 |
+
SearchResult.save(record.degradeForFireStore()).catch((err) => {
|
| 466 |
+
this.logger.warn(`Failed to cache search result`, { err });
|
| 467 |
+
});
|
| 468 |
+
|
| 469 |
+
return r;
|
| 470 |
+
} catch (err: any) {
|
| 471 |
+
if (cache) {
|
| 472 |
+
this.logger.warn(`Failed to fetch search result, but a stale cache is available. falling back to stale cache`, { err: marshalErrorLike(err) });
|
| 473 |
+
|
| 474 |
+
return cache.response as WebSearchApiResponse;
|
| 475 |
+
}
|
| 476 |
+
|
| 477 |
+
throw err;
|
| 478 |
+
}
|
| 479 |
|
|
|
|
| 480 |
}
|
| 481 |
}
|
backend/functions/src/services/brave-search.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import { AsyncService, DownstreamServiceFailureError } from 'civkit';
|
| 2 |
import { singleton } from 'tsyringe';
|
| 3 |
import { Logger } from '../shared/services/logger';
|
| 4 |
import { SecretExposer } from '../shared/services/secrets';
|
|
@@ -62,8 +62,10 @@ export class BraveSearchService extends AsyncService {
|
|
| 62 |
const r = await this.braveSearchHTTP.webSearch(query, { headers: extraHeaders as Record<string, string> });
|
| 63 |
|
| 64 |
return r.parsed;
|
| 65 |
-
} catch (err) {
|
| 66 |
-
|
|
|
|
|
|
|
| 67 |
}
|
| 68 |
|
| 69 |
}
|
|
|
|
| 1 |
+
import { AsyncService, DownstreamServiceFailureError, marshalErrorLike } from 'civkit';
|
| 2 |
import { singleton } from 'tsyringe';
|
| 3 |
import { Logger } from '../shared/services/logger';
|
| 4 |
import { SecretExposer } from '../shared/services/secrets';
|
|
|
|
| 62 |
const r = await this.braveSearchHTTP.webSearch(query, { headers: extraHeaders as Record<string, string> });
|
| 63 |
|
| 64 |
return r.parsed;
|
| 65 |
+
} catch (err: any) {
|
| 66 |
+
this.logger.error(`Web search failed: ${err?.message}`, { err: marshalErrorLike(err) });
|
| 67 |
+
|
| 68 |
+
throw new DownstreamServiceFailureError({ message: `Search failed` });
|
| 69 |
}
|
| 70 |
|
| 71 |
}
|