Skip to content

Commit

Permalink
fix: guards on missing current epoch row
Browse files Browse the repository at this point in the history
  • Loading branch information
rhyslbw committed Apr 21, 2021
1 parent 5e31f37 commit 6204c96
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/api-cardano-db-hasura/src/HasuraClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import { AssetWithoutTokens } from './typeAliases'

export type AdaPotsToCalculateSupply = { circulating: AssetSupply['circulating'], reserves: AdaPots['reserves']}

const notInCurrentEraMessage = 'currentEpoch is only available when close to the chain tip. This is expected during the initial chain-sync.'

export class HasuraClient {
private client: GraphQLClient
private applyingSchemaAndMetadata: boolean
Expand All @@ -44,7 +46,7 @@ export class HasuraClient {
try {
return this.getAdaPotsToCalculateSupply()
} catch (error) {
if (error.message !== 'currentEpoch is only available when close to the chain tip. This is expected during the initial chain-sync.') {
if (error.message !== notInCurrentEraMessage) {
throw error
}
this.logger.debug(error.message)
Expand Down Expand Up @@ -112,6 +114,10 @@ export class HasuraClient {
utxos_aggregate: utxosAggregate,
withdrawals_aggregate: withdrawalsAggregate
} = result
if (cardano[0].currentEpoch === null) {
this.logger.debug(notInCurrentEraMessage)
throw new Error(notInCurrentEraMessage)
}
const rewards = new BigNumber(rewardsAggregate.aggregate.sum.amount)
const utxos = new BigNumber(utxosAggregate.aggregate.sum.value)
const withdrawals = new BigNumber(withdrawalsAggregate.aggregate.sum.amount)
Expand Down Expand Up @@ -161,9 +167,9 @@ export class HasuraClient {
}
}`
)
if (result.cardano.currentEpoch === null) {
this.logger.debug('Not in current era')
throw new Error('Not in current era')
if (result.cardano[0].currentEpoch === null) {
this.logger.debug(notInCurrentEraMessage)
throw new Error(notInCurrentEraMessage)
}
}, {
factor: 1.05,
Expand Down

0 comments on commit 6204c96

Please sign in to comment.