Add revert reason parsing to error handling decorator
This commit is contained in:
		@@ -4,6 +4,7 @@ export const constants = {
 | 
				
			|||||||
    NULL_ADDRESS: '0x0000000000000000000000000000000000000000',
 | 
					    NULL_ADDRESS: '0x0000000000000000000000000000000000000000',
 | 
				
			||||||
    TESTRPC_NETWORK_ID: 50,
 | 
					    TESTRPC_NETWORK_ID: 50,
 | 
				
			||||||
    INVALID_JUMP_PATTERN: 'invalid JUMP at',
 | 
					    INVALID_JUMP_PATTERN: 'invalid JUMP at',
 | 
				
			||||||
 | 
					    REVERT: 'revert',
 | 
				
			||||||
    OUT_OF_GAS_PATTERN: 'out of gas',
 | 
					    OUT_OF_GAS_PATTERN: 'out of gas',
 | 
				
			||||||
    INVALID_TAKER_FORMAT: 'instance.taker is not of a type(s) string',
 | 
					    INVALID_TAKER_FORMAT: 'instance.taker is not of a type(s) string',
 | 
				
			||||||
    // tslint:disable-next-line:custom-no-magic-numbers
 | 
					    // tslint:disable-next-line:custom-no-magic-numbers
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,3 +1,4 @@
 | 
				
			|||||||
 | 
					import { RevertReason } from '@0xproject/types';
 | 
				
			||||||
import * as _ from 'lodash';
 | 
					import * as _ from 'lodash';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { AsyncMethod, ContractWrappersError, SyncMethod } from '../types';
 | 
					import { AsyncMethod, ContractWrappersError, SyncMethod } from '../types';
 | 
				
			||||||
@@ -13,6 +14,10 @@ const contractCallErrorTransformer = (error: Error) => {
 | 
				
			|||||||
    if (_.includes(error.message, constants.OUT_OF_GAS_PATTERN)) {
 | 
					    if (_.includes(error.message, constants.OUT_OF_GAS_PATTERN)) {
 | 
				
			||||||
        return new Error(ContractWrappersError.OutOfGas);
 | 
					        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;
 | 
					    return error;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user