From 0f65e7269001c8544212c89a77a913bf60380c75 Mon Sep 17 00:00:00 2001 From: mihaisc Date: Fri, 21 Oct 2022 14:56:36 +0300 Subject: [PATCH] catch error --- src/mappings/utils/dispenserUtils.ts | 35 +++++++++++++++++----------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/mappings/utils/dispenserUtils.ts b/src/mappings/utils/dispenserUtils.ts index 93c51ee..d8d03f6 100644 --- a/src/mappings/utils/dispenserUtils.ts +++ b/src/mappings/utils/dispenserUtils.ts @@ -1,6 +1,6 @@ import { Dispenser } from '../../@types/schema' import { getToken } from './tokenUtils' -import { Address } from '@graphprotocol/graph-ts' +import { Address, log } from '@graphprotocol/graph-ts' import { weiToDecimal } from './generic' import { Dispenser as DispenserContract } from '../../@types/templates/Dispenser/Dispenser' @@ -29,17 +29,24 @@ export function updateDispenserDetails( contractAddress: Address, datatokenAddress: Address ): void { - const dispenserID = getDispenserGraphID(contractAddress, datatokenAddress) - const dispenser = getDispenser(dispenserID) - const contract = DispenserContract.bind(contractAddress) - const dispenserDetails = contract.try_status(datatokenAddress) - if (dispenserDetails == null) return - const token = getToken(datatokenAddress, true) - dispenser.balance = weiToDecimal( - dispenserDetails.value.value5.toBigDecimal(), - token.decimals - ) - dispenser.isMinter = dispenserDetails.value.value2 - dispenser.active = dispenserDetails.value.value0 - dispenser.save() + try { + const dispenserID = getDispenserGraphID(contractAddress, datatokenAddress) + const dispenser = getDispenser(dispenserID) + const contract = DispenserContract.bind(contractAddress) + const dispenserDetails = contract.try_status(datatokenAddress) + if (dispenserDetails == null) return + const token = getToken(datatokenAddress, true) + dispenser.balance = weiToDecimal( + dispenserDetails.value.value5.toBigDecimal(), + token.decimals + ) + dispenser.isMinter = dispenserDetails.value.value2 + dispenser.active = dispenserDetails.value.value0 + dispenser.save() + } catch (error) { + log.error( + 'Failed to update dispenser details , address: {}, dtAddress: {}', + [contractAddress.toHexString(), datatokenAddress.toString()] + ) + } }