Gathering detailed insights and metrics for eth-rpc-errors
Gathering detailed insights and metrics for eth-rpc-errors
Gathering detailed insights and metrics for eth-rpc-errors
Gathering detailed insights and metrics for eth-rpc-errors
npm install eth-rpc-errors
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
161 Stars
139 Commits
32 Forks
61 Watching
3 Branches
267 Contributors
Updated on 28 Nov 2024
TypeScript (69.77%)
JavaScript (29.42%)
Shell (0.81%)
Cumulative downloads
Total Downloads
Last day
-9.9%
67,107
Compared to previous day
Last week
6.3%
411,954
Compared to previous week
Last month
-2.2%
1,665,404
Compared to previous month
Last year
-29.3%
21,784,961
Compared to previous year
@metamask/rpc-errors
JSON-RPC errors, including for Ethereum JSON RPC and Ethereum Provider, and making unknown errors compliant with either spec.
yarn add @metamask/rpc-errors
or
npm install @metamask/rpc-errors
1import { rpcErrors, providerErrors } from '@metamask/rpc-errors'; 2 3throw rpcErrors.invalidRequest(); 4// or 5throw providerErrors.unauthorized('my custom message');
CloseEvent
errors or status codes.1import { rpcErrors, providerErrors } from '@metamask/rpc-errors'; 2 3// JSON-RPC errors and Ethereum EIP-1474 errors are namespaced under "rpcErrors" 4response.error = rpcErrors.methodNotFound({ 5 message: optionalCustomMessage, 6 data: optionalData, 7}); 8 9// Ethereum EIP-1193 Provider errors namespaced under "providerErrors" 10response.error = providerErrors.unauthorized({ 11 message: optionalCustomMessage, 12 data: optionalData, 13}); 14 15// each error getter takes a single "opts" argument 16// for most errors, this can be replaced with a single string, which becomes 17// the error message 18response.error = providerErrors.unauthorized(customMessage); 19 20// if an error getter accepts a single string, all arguments can be omitted 21response.error = providerErrors.unauthorized(); 22response.error = providerErrors.unauthorized({}); 23 24// omitting the message will produce an error with a default message per 25// the relevant spec 26 27// omitting the data argument will produce an error without a 28// "data" property 29 30// the JSON RPC 2.0 server error requires a valid code 31response.error = rpcErrors.server({ 32 code: -32031, 33}); 34 35// custom Ethereum Provider errors require a valid code and message 36// valid codes are integers i such that: 1000 <= i <= 4999 37response.error = providerErrors.custom({ 38 code: 1001, 39 message: 'foo', 40});
1// this is useful for ensuring your errors are standardized 2import { serializeError } from '@metamask/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 * Classes 3 */ 4import { JsonRpcError, EthereumProviderError } from '@metamask/rpc-errors'; 5 6/** 7 * getMessageFromCode and errorCodes 8 */ 9import { getMessageFromCode, errorCodes } from '@metamask/rpc-errors'; 10 11// get the default message string for the given code, or a fallback message if 12// no message exists for the given code 13const message1 = getMessageFromCode(someCode); 14 15// you can specify your own fallback message 16const message2 = getMessageFromCode(someCode, myFallback); 17// it can be anything, use at your own peril 18const message3 = getMessageFromCode(someCode, null); 19 20// { 21// rpcErrors: { [errorName]: code, ... }, 22// providerErrors: { [errorName]: code, ... }, 23// } 24const code1 = rpcErrors.parse; 25const code2 = providerErrors.userRejectedRequest; 26 27// all codes in errorCodes have default messages 28const message4 = getMessageFromCode(code1); 29const message5 = getMessageFromCode(code2);
nvm use
will automatically choose the right node version for you.yarn install
to install dependencies and run any required post-install scriptsRun yarn test
to run the tests once. To run tests on file changes, run yarn test:watch
.
Run yarn lint
to run the linter, or run yarn lint:fix
to run the linter and fix any automatically fixable issues.
The project follows the same release process as the other libraries in the MetaMask organization. The GitHub Actions action-create-release-pr
and action-publish-release
are used to automate the release process; see those repositories for more information about how they work.
1.x
for a v1
backport release).v1.0.2
release, you'd want to ensure there was a 1.x
branch that was set to the v1.0.1
tag.workflow_dispatch
event manually for the Create Release Pull Request
action to create the release PR.action-create-release-pr
workflow to create the release PR.yarn auto-changelog validate --rc
to check that the changelog is correctly formatted.action-publish-release
workflow to tag the final release commit and publish the release on GitHub.publish-release
GitHub Action workflow to finish. This should trigger a second job (publish-npm
), which will wait for a run approval by the npm publishers
team.publish-npm
job (or ask somebody on the npm publishers team to approve it for you).publish-npm
job has finished, check npm to verify that it has been published.No vulnerabilities found.
No security vulnerabilities found.