diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-05-30 20:48:45 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-05-30 20:48:45 +0800 |
commit | 8c0d783ccc40d5430a5fdc8253968aa457f717bd (patch) | |
tree | cbe3d31d8209d67adf7e799093ff36f26841867c /src | |
parent | 18d65f5f55bcdbbb1e1058ac9e8fe193804b1a06 (diff) | |
download | dexon-sol-tools-8c0d783ccc40d5430a5fdc8253968aa457f717bd.tar.gz dexon-sol-tools-8c0d783ccc40d5430a5fdc8253968aa457f717bd.tar.zst dexon-sol-tools-8c0d783ccc40d5430a5fdc8253968aa457f717bd.zip |
Add throwErrorLogsAsErrors
Diffstat (limited to 'src')
-rw-r--r-- | src/contract_wrappers/exchange_wrapper.ts | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index 141e9502a..7a80c5800 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -7,6 +7,7 @@ import { OrderValues, OrderAddresses, SignedOrder, + ContractEvent, } from '../types'; import {assert} from '../utils/assert'; import {ContractWrapper} from './contract_wrapper'; @@ -86,16 +87,19 @@ export class ExchangeWrapper extends ContractWrapper { from: senderAddress, }, ); - const errEvent = _.find(response.logs, {event: 'LogError'}); - if (!_.isUndefined(errEvent)) { - const errCode = errEvent.args.errorId.toNumber(); - const humanReadableErrMessage = this.exchangeContractErrToMsg[errCode]; - throw new Error(humanReadableErrMessage); - } + this.throwErrorLogsAsErrors(response.logs); return response; } private async getExchangeInstanceOrThrowAsync(): Promise<ExchangeContract> { const contractInstance = await this.instantiateContractIfExistsAsync((ExchangeArtifacts as any)); return contractInstance as ExchangeContract; } + private throwErrorLogsAsErrors(logs: ContractEvent[]): void { + const errEvent = _.find(logs, {event: 'LogError'}); + if (!_.isUndefined(errEvent)) { + const errCode = errEvent.args.errorId.toNumber(); + const humanReadableErrMessage = this.exchangeContractErrToMsg[errCode]; + throw new Error(humanReadableErrMessage); + } + } } |