How to use the common-errors.ConnectionError function in common-errors

To help you get started, we’ve selected a few common-errors examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ubiq / shokku / src / server / services / jsonrpc.js View on Github external
const response = await web3[opts.network].safe[opts.method].apply(this, opts.params)
      return {
        id: opts.id || this.randomId(),
        jsonrpc: '2.0',
        result: response
      }
    } catch (err) {
      const errMsg = err.message.replace(/"/g, "'")
      l.error('JsonRpcService - method() / ', errMsg)
      let error
      if (errMsg.match(/^Returned error/)) {
        error = new errors.Error(err.message)
      } else if (errMsg.match(/^Invalid number of parameters/)) {
        error = new errors.ArgumentError('Invalid number of params used', err)
      } else if (errMsg.match(/^(?:CONNECTION ERROR|CONNECTION TIMEOUT|Provider not set or invalid)/)) {
        error = new errors.ConnectionError('Impossible to connect to node.', err)
      } else if (errMsg.match(/^Invalid JSON RPC response/)) {
        error = new errors.InvalidOperationError('Invalid JSON RPC response', err)
      } else {
        error = new errors.Error('Invalid JSON RPC response from node')
      }
      throw error
    }
  }