@0x/base-contract: Re-wrap StringRevertErrors as plain Errors for backwards compatibility

This commit is contained in:
Lawrence Forman 2019-05-18 03:18:47 -04:00 committed by Amir Bandeali
parent aebb923c2d
commit 3de13967bc

View File

@ -8,6 +8,7 @@ import {
decodeThrownErrorAsRevertError, decodeThrownErrorAsRevertError,
providerUtils, providerUtils,
RevertError, RevertError,
StringRevertError,
} from '@0x/utils'; } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper'; import { Web3Wrapper } from '@0x/web3-wrapper';
import { import {
@ -128,6 +129,10 @@ export class BaseContract {
let revertError: RevertError; let revertError: RevertError;
try { try {
revertError = decodeThrownErrorAsRevertError(error); revertError = decodeThrownErrorAsRevertError(error);
// Re-cast StringRevertErrors as plain Errors for backwards-compatibility.
if (revertError instanceof StringRevertError) {
throw new Error(revertError.values.message as string);
}
} catch (err) { } catch (err) {
// Can't decode it. // Can't decode it.
return; return;