mirror of
https://github.com/intergalacticalvariable/reader.git
synced 2024-11-16 11:42:32 +08:00
fix: logging for search error
This commit is contained in:
parent
e0e37ad4d7
commit
8ec8c1e718
|
@ -451,20 +451,31 @@ ${this.content}
|
|||
}
|
||||
}
|
||||
|
||||
const r = await this.braveSearchService.webSearch(query);
|
||||
try {
|
||||
const r = await this.braveSearchService.webSearch(query);
|
||||
|
||||
const nowDate = new Date();
|
||||
const record = SearchResult.from({
|
||||
query,
|
||||
queryDigest,
|
||||
response: r,
|
||||
createdAt: nowDate,
|
||||
expireAt: new Date(nowDate.valueOf() + this.cacheRetentionMs)
|
||||
});
|
||||
SearchResult.save(record.degradeForFireStore()).catch((err) => {
|
||||
this.logger.warn(`Failed to cache search result`, { err });
|
||||
});
|
||||
const nowDate = new Date();
|
||||
const record = SearchResult.from({
|
||||
query,
|
||||
queryDigest,
|
||||
response: r,
|
||||
createdAt: nowDate,
|
||||
expireAt: new Date(nowDate.valueOf() + this.cacheRetentionMs)
|
||||
});
|
||||
SearchResult.save(record.degradeForFireStore()).catch((err) => {
|
||||
this.logger.warn(`Failed to cache search result`, { err });
|
||||
});
|
||||
|
||||
return r;
|
||||
} catch (err: any) {
|
||||
if (cache) {
|
||||
this.logger.warn(`Failed to fetch search result, but a stale cache is available. falling back to stale cache`, { err: marshalErrorLike(err) });
|
||||
|
||||
return cache.response as WebSearchApiResponse;
|
||||
}
|
||||
|
||||
throw err;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { AsyncService, DownstreamServiceFailureError } from 'civkit';
|
||||
import { AsyncService, DownstreamServiceFailureError, marshalErrorLike } from 'civkit';
|
||||
import { singleton } from 'tsyringe';
|
||||
import { Logger } from '../shared/services/logger';
|
||||
import { SecretExposer } from '../shared/services/secrets';
|
||||
|
@ -62,8 +62,10 @@ export class BraveSearchService extends AsyncService {
|
|||
const r = await this.braveSearchHTTP.webSearch(query, { headers: extraHeaders as Record<string, string> });
|
||||
|
||||
return r.parsed;
|
||||
} catch (err) {
|
||||
throw new DownstreamServiceFailureError({ message: `Search failed`, cause: err });
|
||||
} catch (err: any) {
|
||||
this.logger.error(`Web search failed: ${err?.message}`, { err: marshalErrorLike(err) });
|
||||
|
||||
throw new DownstreamServiceFailureError({ message: `Search failed` });
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user