Gathering detailed insights and metrics for eth-json-rpc-errors
Gathering detailed insights and metrics for eth-json-rpc-errors
npm install eth-json-rpc-errors
Typescript
Module System
Node Version
NPM Version
97.8
Supply Chain
100
Quality
79.3
Maintenance
100
Vulnerability
100
License
TypeScript (69.77%)
JavaScript (29.42%)
Shell (0.81%)
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Total Downloads
9,968,169
Last Day
3,488
Last Week
27,379
Last Month
90,088
Last Year
893,232
MIT License
165 Stars
143 Commits
34 Forks
65 Watchers
5 Branches
293 Contributors
Updated on Feb 27, 2025
Minified
Minified + Gzipped
Latest Version
2.0.2
Package Id
eth-json-rpc-errors@2.0.2
Size
9.82 kB
NPM Version
6.13.6
Node Version
13.7.0
Published on
Feb 12, 2020
Cumulative downloads
Total Downloads
Last Day
55.1%
3,488
Compared to previous day
Last Week
-4.4%
27,379
Compared to previous week
Last Month
20.7%
90,088
Compared to previous month
Last Year
-29.7%
893,232
Compared to previous year
1
4
Errors for the Ethereum JSON RPC and Ethereum Provider, and making unknown errors compliant with either spec.
1import { ethErrors } from 'eth-json-rpc-errors' 2 3throw ethErrors.provider.unauthorized() 4// or 5throw ethErrors.provider.unauthorized('my custom message')
CloseEvent
errors or status codes.Installation: npm install eth-json-rpc-errors
or yarn add eth-json-rpc-errors
Import using ES6 syntax (no default export) or Node require
.
1import { ethErrors } from 'eth-json-rpc-errors' 2 3// Ethereum RPC errors are namespaced under "ethErrors.rpc" 4response.error = ethErrors.rpc.methodNotFound({ 5 message: optionalCustomMessage, data: optionalData 6}) 7 8// ETH JSON RPC errors namespaced under ethErrors.provider 9response.error = ethErrors.provider.unauthorized({ 10 message: optionalCustomMessage, data: optionalData 11}) 12 13// each error getter takes a single "opts" argument 14// for most errors, this can be replaced with a single string, which becomes 15// the error message 16response.error = ethErrors.provider.unauthorized(customMessage) 17 18// if an error getter accepts a single string, all arguments can be omitted 19response.error = ethErrors.provider.unauthorized() 20response.error = ethErrors.provider.unauthorized({}) 21 22// omitting the message will produce an error with a default message per 23// the relevant spec 24 25// omitting the data argument will produce an error without a 26// "data" property 27 28// the JSON RPC 2.0 server error requires a valid code 29response.error = ethErrors.rpc.server({ 30 code: -32031 31}) 32 33// custom Ethereum Provider errors require a valid code and message 34// valid codes are integers i such that: 1000 <= i <= 4999 35response.error = ethErrors.provider.custom({ 36 code: 1001, message: 'foo' 37})
1// this is useful for ensuring your errors are standardized 2import { serializeError } from 'eth-json-rpc-errors' 3 4// if the argument is not a valid error per any supported spec, 5// it will be added as error.data.originalError 6response.error = serializeError(maybeAnError) 7 8// you can add a custom fallback error code and message if desired 9const fallbackError = { code: 4999, message: 'My custom error.' } 10response.error = serializeError(maybeAnError, fallbackError) 11 12// Note: if the original error has a "message" property, it will take 13// precedence over the fallback error's message 14 15// the default fallback is: 16{ 17 code: -32603, 18 message: 'Internal JSON-RPC error.' 19}
1/**
2 * TypeScript interfaces
3 */
4import {
5 // these describe to the corresponding exports from index.js
6 IEthErrors, IEthereumRpcError, IEthereumProviderError, ISerializeError,
7 // these describe the options argument to error getters in ethErrors
8 IErrorOptions, IRpcServerErrorOptions, IProviderCustomErrorOptions
9} from 'eth-json-rpc-errors/@types'
10
11/**
12 * Classes
13 */
14import { EthereumRpcError, EthereumProviderError } from 'eth-json-rpc-errors'
15
16/**
17 * getMessageFromCode & ERROR_CODES
18 */
19import { getMessageFromCode, ERROR_CODES } from 'eth-json-rpc-errors'
20
21// get the default message string for the given code, or a fallback message if
22// no message exists for the given code
23const message1 = getMessageFromCode(someCode)
24
25// you can specify your own fallback message
26const message2 = getMessageFromCode(someCode, myFallback)
27// it can be anything, use at your own peril
28const message3 = getMessageFromCode(someCode, null)
29
30// {
31// jsonRpc: { [errorName]: code, ... },
32// eth: { [errorName]: code, ... },
33// }
34const code1 = ERROR_CODES.rpc.parse
35const code2 = ERROR_CODES.provider.userRejectedRequest
36
37// all codes in ERROR_CODES have default messages
38const message4 = getMessageFromCode(code1)
39const message5 = getMessageFromCode(code2)
MIT
No vulnerabilities found.
No security vulnerabilities found.