aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/extractEthjsErrorMessage.js
diff options
context:
space:
mode:
authorDan Finlay <542863+danfinlay@users.noreply.github.com>2018-04-25 00:51:18 +0800
committerGitHub <noreply@github.com>2018-04-25 00:51:18 +0800
commitac334d7b1a9cd8b6888f5c4f3309740d5df62474 (patch)
tree7498f29e899821d879b3f68a42b8995f42f80321 /app/scripts/lib/extractEthjsErrorMessage.js
parent66ae4a948abbebdb513f9bd60d47fda36095e8df (diff)
parent0fbd389a509a2447d833192bbe854c586890d512 (diff)
downloadtangerine-wallet-browser-ac334d7b1a9cd8b6888f5c4f3309740d5df62474.tar.gz
tangerine-wallet-browser-ac334d7b1a9cd8b6888f5c4f3309740d5df62474.tar.zst
tangerine-wallet-browser-ac334d7b1a9cd8b6888f5c4f3309740d5df62474.zip
Merge pull request #4040 from MetaMask/dm-docs-2
Even more documentation for various controllers and libs.
Diffstat (limited to 'app/scripts/lib/extractEthjsErrorMessage.js')
-rw-r--r--app/scripts/lib/extractEthjsErrorMessage.js23
1 files changed, 12 insertions, 11 deletions
diff --git a/app/scripts/lib/extractEthjsErrorMessage.js b/app/scripts/lib/extractEthjsErrorMessage.js
index bac541735..0f100756f 100644
--- a/app/scripts/lib/extractEthjsErrorMessage.js
+++ b/app/scripts/lib/extractEthjsErrorMessage.js
@@ -4,17 +4,18 @@ const errorLabelPrefix = 'Error: '
module.exports = extractEthjsErrorMessage
-//
-// ethjs-rpc provides overly verbose error messages
-// if we detect this type of message, we extract the important part
-// Below is an example input and output
-//
-// Error: [ethjs-rpc] rpc error with payload {"id":3947817945380,"jsonrpc":"2.0","params":["0xf8eb8208708477359400830398539406012c8cf97bead5deae237070f9587f8e7a266d80b8843d7d3f5a0000000000000000000000000000000000000000000000000000000000081d1a000000000000000000000000000000000000000000000000001ff973cafa800000000000000000000000000000000000000000000000000000038d7ea4c68000000000000000000000000000000000000000000000000000000000000003f48025a04c32a9b630e0d9e7ff361562d850c86b7a884908135956a7e4a336fa0300d19ca06830776423f25218e8d19b267161db526e66895567147015b1f3fc47aef9a3c7"],"method":"eth_sendRawTransaction"} Error: replacement transaction underpriced
-//
-// Transaction Failed: replacement transaction underpriced
-//
-
-
+/**
+ * Extracts the important part of an ethjs-rpc error message. If the passed error is not an isEthjsRpcError, the error
+ * is returned unchanged.
+ *
+ * @param {string} errorMessage The error message to parse
+ * @returns {string} Returns an error message, either the same as was passed, or the ending message portion of an isEthjsRpcError
+ *
+ * @example
+ * // returns 'Transaction Failed: replacement transaction underpriced'
+ * extractEthjsErrorMessage(`Error: [ethjs-rpc] rpc error with payload {"id":3947817945380,"jsonrpc":"2.0","params":["0xf8eb8208708477359400830398539406012c8cf97bead5deae237070f9587f8e7a266d80b8843d7d3f5a0000000000000000000000000000000000000000000000000000000000081d1a000000000000000000000000000000000000000000000000001ff973cafa800000000000000000000000000000000000000000000000000000038d7ea4c68000000000000000000000000000000000000000000000000000000000000003f48025a04c32a9b630e0d9e7ff361562d850c86b7a884908135956a7e4a336fa0300d19ca06830776423f25218e8d19b267161db526e66895567147015b1f3fc47aef9a3c7"],"method":"eth_sendRawTransaction"} Error: replacement transaction underpriced`)
+ *
+*/
function extractEthjsErrorMessage(errorMessage) {
const isEthjsRpcError = errorMessage.includes(ethJsRpcSlug)
if (isEthjsRpcError) {