Skip to content

Commit 31f39a5

Browse files
author
Alan Shaw
authored
fix: fdw fault tolerance (#2108)
1 parent 7ecb3d9 commit 31f39a5

1 file changed

Lines changed: 20 additions & 16 deletions

File tree

packages/api/src/utils/db-client.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -498,25 +498,29 @@ export class DBClient {
498498
* @param {string[]} cids
499499
*/
500500
async getDealsForCids(cids = []) {
501-
const rsp = await this.client.rpc('find_deals_by_content_cids', {
502-
cids,
503-
})
504-
if (rsp.error) {
505-
return {}
506-
}
501+
try {
502+
const rsp = await this.client.rpc('find_deals_by_content_cids', {
503+
cids,
504+
})
505+
if (rsp.error) {
506+
throw new DBError(rsp.error)
507+
}
507508

508-
/** @type {Record<string, import('./../bindings').Deal[]>} */
509-
const result = {}
510-
for (const d of rsp.data) {
511-
const { contentCid: cid, ...rest } = d
512-
if (!Array.isArray(result[cid])) {
513-
result[cid] = [rest]
514-
} else {
515-
result[cid].push(rest)
509+
/** @type {Record<string, import('./../bindings').Deal[]>} */
510+
const result = {}
511+
for (const d of rsp.data) {
512+
const { contentCid: cid, ...rest } = d
513+
if (!Array.isArray(result[cid])) {
514+
result[cid] = [rest]
515+
} else {
516+
result[cid].push(rest)
517+
}
516518
}
517-
}
518519

519-
return result
520+
return result
521+
} catch (err) {
522+
return {}
523+
}
520524
}
521525

522526
/**

0 commit comments

Comments
 (0)