Merge pull request #4126 from omnivore-app/fix/digest-score-client-fallback

fix: returns a stub score (0) for "each item" in case score api throws an error
This commit is contained in:
Hongbo Wu 2024-07-01 15:39:10 +08:00 committed by GitHub
commit b3c2e34c10
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 4 deletions

View file

@ -248,7 +248,7 @@ const rankCandidates = async (
const scores = await scoreClient.getScores(data)
// update scores for candidates
candidates.forEach((item) => {
item.score = scores[item.id].score || 0
item.score = scores[item.id]?.score || 0
})
// rank candidates by score in descending order

View file

@ -90,9 +90,10 @@ class ScoreClientImpl implements ScoreClient {
logError(error)
// Returns a stub score (0) in case of an error
return {
[Object.keys(data.items)[0]]: { score: 0 },
}
return Object.keys(data.items).reduce((acc, itemId) => {
acc[itemId] = { score: 0 }
return acc
}, {} as ScoreApiResponse)
} finally {
const duration = (Date.now() - start) / 1000 // in seconds
latency.observe(duration)