@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,
providerUtils,
RevertError,
StringRevertError,
} from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
import {
@@ -128,6 +129,10 @@ export class BaseContract {
let revertError: RevertError;
try {
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) {
// Can't decode it.
return;