Skip to content

Commit

Permalink
fix(api): improve error handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommytrg committed Aug 19, 2021
1 parent 37bfa51 commit 89e2026
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions packages/api/src/web3Middleware/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,9 @@ export class Web3Middleware {
drTxHash: toHex(drTxHash).slice(2)
}
} catch (err) {
console.log('[ERROR]', err)
return {
lastPrice: null,
lastTimestamp: null,
lastRequestId: null,
drTxHash: null
}
throw new Error(
`Error reading contract state`
)
}
}

Expand All @@ -144,28 +140,32 @@ export class Web3Middleware {
address: string
}
) {
const {
drTxHash,
lastPrice,
lastRequestId,
lastTimestamp
}: ContractsState = await this.readContractsState(contracts)
const address = feed.address
const lastStoredResult = this.lastStoredResult[address]

const isAlreadyStored = lastStoredResult?.timestamp === lastTimestamp
const isDrSolved = drTxHash !== '0'
if (!isAlreadyStored && isDrSolved) {
const result = await this.repositories.resultRequestRepository.insert({
feedId: feed.id.toString(),
result: lastPrice,
timestamp: lastTimestamp,
requestId: lastRequestId,
address: feed.address,
drTxHash: drTxHash,
label: feed.label
})
this.lastStoredResult[feed.address] = result
try {
const {
drTxHash,
lastPrice,
lastRequestId,
lastTimestamp
}: ContractsState = await this.readContractsState(contracts)
const address = feed.address
const lastStoredResult = this.lastStoredResult[address]

const isAlreadyStored = lastStoredResult?.timestamp === lastTimestamp
const isDrSolved = drTxHash !== '0'
if (!isAlreadyStored && isDrSolved) {
const result = await this.repositories.resultRequestRepository.insert({
feedId: feed.id.toString(),
result: lastPrice,
timestamp: lastTimestamp,
requestId: lastRequestId,
address: feed.address,
drTxHash: drTxHash,
label: feed.label
})
this.lastStoredResult[feed.address] = result
}
} catch (error) {
console.error(`Error reading contracts state: ${feed}`)
}
}
}

0 comments on commit 89e2026

Please sign in to comment.