mirror of
https://git.mirrors.martin98.com/https://github.com/jina-ai/reader
synced 2025-08-18 08:46:00 +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 nowDate = new Date();
|
||||||
const record = SearchResult.from({
|
const record = SearchResult.from({
|
||||||
query,
|
query,
|
||||||
queryDigest,
|
queryDigest,
|
||||||
response: r,
|
response: r,
|
||||||
createdAt: nowDate,
|
createdAt: nowDate,
|
||||||
expireAt: new Date(nowDate.valueOf() + this.cacheRetentionMs)
|
expireAt: new Date(nowDate.valueOf() + this.cacheRetentionMs)
|
||||||
});
|
});
|
||||||
SearchResult.save(record.degradeForFireStore()).catch((err) => {
|
SearchResult.save(record.degradeForFireStore()).catch((err) => {
|
||||||
this.logger.warn(`Failed to cache search result`, { 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 { singleton } from 'tsyringe';
|
||||||
import { Logger } from '../shared/services/logger';
|
import { Logger } from '../shared/services/logger';
|
||||||
import { SecretExposer } from '../shared/services/secrets';
|
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> });
|
const r = await this.braveSearchHTTP.webSearch(query, { headers: extraHeaders as Record<string, string> });
|
||||||
|
|
||||||
return r.parsed;
|
return r.parsed;
|
||||||
} catch (err) {
|
} catch (err: any) {
|
||||||
throw new DownstreamServiceFailureError({ message: `Search failed`, cause: err });
|
this.logger.error(`Web search failed: ${err?.message}`, { err: marshalErrorLike(err) });
|
||||||
|
|
||||||
|
throw new DownstreamServiceFailureError({ message: `Search failed` });
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user