Skip to content

Commit

Permalink
Rethrow errors in asyncRetry (#4189)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaylor89 committed Oct 26, 2022
1 parent 3a17a78 commit 4a374fd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 7 additions & 2 deletions creator-node/src/services/ContentNodeInfoManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export async function getReplicaSetSpIdsByUserId({

let errorMsg = null
await asyncRetry({
logLabel: 'getReplicaSetSpIdsByUserId',
options: {
retries: MAX_RETRIES
},
Expand Down Expand Up @@ -203,7 +204,8 @@ export async function getReplicaSetSpIdsByUserId({
}
} catch (e: any) {
errorMsg = e.message
} // Ignore all errors until MAX_RETRIES exceeded
throw e
}
}
})

Expand All @@ -222,6 +224,7 @@ export async function getReplicaSetSpIdsByUserId({
const MAX_RETRIES = 10
let errorMsg = null
await asyncRetry({
logLabel: 'getReplicaSetSpIdsByUserId',
options: {
retries: MAX_RETRIES
},
Expand All @@ -244,10 +247,12 @@ export async function getReplicaSetSpIdsByUserId({
if (replicaSet.primaryId === selfSpId) return
} else {
errorMsg = 'User replica not found in discovery'
throw new Error(errorMsg)
}
} catch (e: any) {
errorMsg = e.message
} // Ignore all errors until MAX_RETRIES exceeded
throw e
}
}
})

Expand Down
5 changes: 2 additions & 3 deletions creator-node/src/utils/asyncRetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ export function asyncRetry({
onRetry: (err: any, i: number) => {
if (err && log) {
const logPrefix =
(logLabel ? `[${logLabel}] ` : '') +
`[asyncRetry:${asyncFn.name}] [attempt #${i}]`
logger.warn(`${logPrefix}: `, err.message || err)
(logLabel ? `[${logLabel}] ` : '') + `[asyncRetry] [attempt #${i}]`
logger.debug(`${logPrefix}: `, err.message || err)
}
},
...options
Expand Down

0 comments on commit 4a374fd

Please sign in to comment.