diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-03-09 22:37:46 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-03-12 10:37:28 +0800 |
commit | b4cb88ab26a08851ab02e19e7105d29f8ee94184 (patch) | |
tree | 189ed5147858cd0c17a9e090bc0e7264ebb2f1fc | |
parent | ad4f60764361881f1406c16baed1f8b0d2e14c9b (diff) | |
download | dexon-0x-contracts-b4cb88ab26a08851ab02e19e7105d29f8ee94184.tar.gz dexon-0x-contracts-b4cb88ab26a08851ab02e19e7105d29f8ee94184.tar.zst dexon-0x-contracts-b4cb88ab26a08851ab02e19e7105d29f8ee94184.zip |
Add better error handling in deployer constructor
-rw-r--r-- | packages/deployer/src/deployer.ts | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/packages/deployer/src/deployer.ts b/packages/deployer/src/deployer.ts index 4d0f4cfe4..b72219d6e 100644 --- a/packages/deployer/src/deployer.ts +++ b/packages/deployer/src/deployer.ts @@ -28,9 +28,18 @@ export class Deployer { this._artifactsDir = opts.artifactsDir; this._networkId = opts.networkId; this._defaults = opts.defaults; - const web3Provider = _.isUndefined((opts as ProviderDeployerOptions).web3Provider) - ? new Web3.providers.HttpProvider(`http://localhost:${(opts as PortDeployerOptions).jsonrpcPort}`) - : (opts as ProviderDeployerOptions).web3Provider; + let web3Provider: Web3.Provider; + if (_.isUndefined((opts as ProviderDeployerOptions).web3Provider)) { + const jsonrpcPort = (opts as PortDeployerOptions).jsonrpcPort; + if (_.isUndefined(jsonrpcPort)) { + throw new Error( + `Deployer options don't have neither web3Provider nor jsonrpcPort. Please pass one of them`, + ); + } + web3Provider = new Web3.providers.HttpProvider(`http://localhost:${jsonrpcPort}`); + } else { + web3Provider = (opts as ProviderDeployerOptions).web3Provider; + } this.web3Wrapper = new Web3Wrapper(web3Provider, this._defaults); } /** |