Add revert reason parsing to error handling decorator

This commit is contained in:
Leonid Logvinov
2018-07-09 10:46:15 +02:00
parent 258fe8ea50
commit ab1e38701d
2 changed files with 6 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ export const constants = {
NULL_ADDRESS: '0x0000000000000000000000000000000000000000',
TESTRPC_NETWORK_ID: 50,
INVALID_JUMP_PATTERN: 'invalid JUMP at',
REVERT: 'revert',
OUT_OF_GAS_PATTERN: 'out of gas',
INVALID_TAKER_FORMAT: 'instance.taker is not of a type(s) string',
// tslint:disable-next-line:custom-no-magic-numbers

View File

@@ -1,3 +1,4 @@
import { RevertReason } from '@0xproject/types';
import * as _ from 'lodash';
import { AsyncMethod, ContractWrappersError, SyncMethod } from '../types';
@@ -13,6 +14,10 @@ const contractCallErrorTransformer = (error: Error) => {
if (_.includes(error.message, constants.OUT_OF_GAS_PATTERN)) {
return new Error(ContractWrappersError.OutOfGas);
}
if (_.includes(error.message, constants.REVERT)) {
const revertReason = error.message.split(constants.REVERT)[1].trim();
return new Error(revertReason);
}
return error;
};