aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-07-09 16:46:15 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-07-09 17:13:21 +0800
commitab1e38701d40692be0f0e3f2939fda90084564af (patch)
tree3850a764d8b0a3d98a9b75967c88718d12eef302
parent258fe8ea50f3cf2a78649827c3a7899ebc7a7734 (diff)
downloaddexon-sol-tools-ab1e38701d40692be0f0e3f2939fda90084564af.tar.gz
dexon-sol-tools-ab1e38701d40692be0f0e3f2939fda90084564af.tar.zst
dexon-sol-tools-ab1e38701d40692be0f0e3f2939fda90084564af.zip
Add revert reason parsing to error handling decorator
-rw-r--r--packages/contract-wrappers/src/utils/constants.ts1
-rw-r--r--packages/contract-wrappers/src/utils/decorators.ts5
2 files changed, 6 insertions, 0 deletions
diff --git a/packages/contract-wrappers/src/utils/constants.ts b/packages/contract-wrappers/src/utils/constants.ts
index 76d805cac..039475b7f 100644
--- a/packages/contract-wrappers/src/utils/constants.ts
+++ b/packages/contract-wrappers/src/utils/constants.ts
@@ -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
diff --git a/packages/contract-wrappers/src/utils/decorators.ts b/packages/contract-wrappers/src/utils/decorators.ts
index ccb4c6e11..6e77450e8 100644
--- a/packages/contract-wrappers/src/utils/decorators.ts
+++ b/packages/contract-wrappers/src/utils/decorators.ts
@@ -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;
};