How to use the common-errors.NotPermittedError 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
async method(opts = {
    network: 'mn',
    method: '',
    params: ''
  }) {
    l.info(`JsonRpcService - method() / Current params: Network - ${opts.network} | Method - ${opts.method} | Params - ${opts.params}`)

    const isSafe = web3[opts.network].safe[opts.method]
    if (!isSafe) {
      l.error(`JsonRpcService - method() / Requested method is not safe. Method: ${opts.method}`)
      const msg = 'Bad JSON RPC method called. Please check the list of compatible methods doing a GET request in /jsonrpc/{network}/methods.'
      throw new errors.NotPermittedError(msg)
    }

    try {
      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/)) {