aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/extractEthjsErrorMessage.js
blob: 4891075c3f6d2e48d019f049673c12e83fc5ad11 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const ethJsRpcSlug = 'Error: [ethjs-rpc] rpc error with payload '
const errorLabelPrefix = 'Error: '

module.exports = extractEthjsErrorMessage


/**
 * 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) {
    const payloadAndError = errorMessage.slice(ethJsRpcSlug.length)
    const originalError = payloadAndError.slice(payloadAndError.indexOf(errorLabelPrefix) + errorLabelPrefix.length)
    return originalError
  } else {
    return errorMessage
  }
}
ef='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/commit/deskutils/calcurse?id=02a06c807cb2fac717917e60c69b41048dfbf4fe'>Update my MAINTAINER address to culot@FreeBSD.org.Frederic Culot2010-10-201-1/+1 * Update COMMENT and pkg-descrMax Brazhnikov2010-07-282-9/+7 * - Update to 2.8Martin Wilke2010-06-062-17/+16 * Bounce PORTREVISION for gettext-related ports. Have fun, ya'll.Ade Lovett2010-05-311-0/+1 * - Update to 2.7Martin Wilke2010-02-022-4/+4 * - Update to version 2.5Beech Rintoul2009-01-262-4/+4 * - Update to 2.4Dmitry Marakasov2009-01-202-5/+4 * Update CONFIGURE_ARGS for how we pass CONFIGURE_TARGET to configure script.Rong-En Fan2008-08-211-1/+0 * Bump portrevision due to upgrade of devel/gettext.Edwin Groothuis2008-06-061-0/+1 * - Update to 2.1Philippe Audeoud2008-05-213-4/+17 * - Update to 1.9Martin Wilke2007-12-133-4/+5 * Remove always-false/true conditions based on OSVERSION 500000Edwin Groothuis2007-10-041-7/+1 * - Update to 1.8Martin Wilke2007-05-30