Skip to content

Commit

Permalink
fix: tolerant of failure for deals
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Dec 9, 2021
1 parent 34f5f82 commit 3fe6d6e
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ export class DBClient {
* @returns {Promise<import('./db-client-types').ContentItemOutput>}
*/
async getStatus (cid) {
/** @type {{ data: import('./db-client-types').ContentItem, error: PostgrestError }} */
/** @type {{ data: Array<import('./db-client-types').ContentItem>, error: PostgrestError }} */
const { data, error } = await this._client
.from('content')
.select(`
Expand All @@ -301,19 +301,18 @@ export class DBClient {
pins:pin(status, updated:updated_at, location:pin_location(peerId:peer_id, peerName:peer_name, region))
`)
.match({ cid })
.single()

if (error) {
throw new DBError(error)
}

if (!data) {
return
if (!data || !data.length) {
return undefined;
}

const deals = await this.getDeals(cid)
return {
...normalizeContent(data),
...normalizeContent(data[0]),
deals
}
}
Expand Down Expand Up @@ -549,7 +548,9 @@ export class DBClient {
}

/**
* Get deals for multiple cids
* Get deals for multiple cids. This function is error tolerant as it uses
* the dagcargo FDW. It will return an empty object if any error is
* encountered fetching the data.
*
* @param {string[]} cids
* @return {Promise<Record<string, import('./db-client-types').Deal[]>>}
Expand All @@ -562,7 +563,7 @@ export class DBClient {
})

if (error) {
throw new DBError(error)
return {}
}

const result = {}
Expand Down

0 comments on commit 3fe6d6e

Please sign in to comment.