From 58c5fe01bf6d399c6206e0593e60e05d256af2b0 Mon Sep 17 00:00:00 2001 From: Erik Marks Date: Mon, 16 Sep 2019 14:07:44 -0700 Subject: [PATCH] use eth-json-rpc-errors --- app/scripts/controllers/provider-approval.js | 3 ++- app/scripts/controllers/transactions/index.js | 7 ++++--- package.json | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/scripts/controllers/provider-approval.js b/app/scripts/controllers/provider-approval.js index 3beda6d53..6b5007051 100644 --- a/app/scripts/controllers/provider-approval.js +++ b/app/scripts/controllers/provider-approval.js @@ -1,6 +1,7 @@ const ObservableStore = require('obs-store') const SafeEventEmitter = require('safe-event-emitter') const createAsyncMiddleware = require('json-rpc-engine/src/createAsyncMiddleware') +const { errors: rpcErrors } = require('eth-json-rpc-errors') /** * A controller that services user-approved requests for a full Ethereum provider API @@ -48,7 +49,7 @@ class ProviderApprovalController extends SafeEventEmitter { if (approved) { res.result = [this.preferencesController.getSelectedAddress()] } else { - throw new Error('User denied account authorization') + throw rpcErrors.eth.userRejectedRequest('User denied account authorization') } }) } diff --git a/app/scripts/controllers/transactions/index.js b/app/scripts/controllers/transactions/index.js index a33b46851..008d1c72d 100644 --- a/app/scripts/controllers/transactions/index.js +++ b/app/scripts/controllers/transactions/index.js @@ -3,6 +3,7 @@ const ObservableStore = require('obs-store') const ethUtil = require('ethereumjs-util') const Transaction = require('ethereumjs-tx') const EthQuery = require('ethjs-query') +const { errors: rpcErrors } = require('eth-json-rpc-errors') const abi = require('human-standard-token-abi') const abiDecoder = require('abi-decoder') abiDecoder.addABI(abi) @@ -166,11 +167,11 @@ class TransactionController extends EventEmitter { case 'submitted': return resolve(finishedTxMeta.hash) case 'rejected': - return reject(cleanErrorStack(new Error('MetaMask Tx Signature: User denied transaction signature.'))) + return reject(cleanErrorStack(rpcErrors.eth.userRejectedRequest('MetaMask Tx Signature: User denied transaction signature.'))) case 'failed': - return reject(cleanErrorStack(new Error(finishedTxMeta.err.message))) + return reject(cleanErrorStack(rpcErrors.internal(finishedTxMeta.err.message))) default: - return reject(cleanErrorStack(new Error(`MetaMask Tx Signature: Unknown problem: ${JSON.stringify(finishedTxMeta.txParams)}`))) + return reject(cleanErrorStack(rpcErrors.internal(`MetaMask Tx Signature: Unknown problem: ${JSON.stringify(finishedTxMeta.txParams)}`))) } }) }) diff --git a/package.json b/package.json index 221ae2e44..48dae1376 100644 --- a/package.json +++ b/package.json @@ -51,11 +51,11 @@ "3box/ipfs/ipld-zcash/zcash-bitcore-lib/lodash": "^4.17.12" }, "dependencies": { + "3box": "^1.10.2", "@babel/runtime": "^7.5.5", "@material-ui/core": "1.0.0", "@sentry/browser": "^4.1.1", "@zxing/library": "^0.8.0", - "3box": "^1.10.2", "abi-decoder": "^1.2.0", "abortcontroller-polyfill": "^1.3.0", "asmcrypto.js": "^2.3.2", @@ -85,6 +85,7 @@ "eth-block-tracker": "^4.4.2", "eth-contract-metadata": "^1.9.2", "eth-ens-namehash": "^2.0.8", + "eth-json-rpc-errors": "^1.0.1", "eth-json-rpc-filters": "^4.1.0", "eth-json-rpc-infura": "^4.0.1", "eth-json-rpc-middleware": "^4.2.0",