11# eth-json-rpc-errors
22
33Errors for the
4- [ Ethereum JSON RPC] ( https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1474.md )
4+ [ Ethereum JSON RPC] ( https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1474.md )
55and
66[ Ethereum Provider] ( https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1193.md ) ,
77and [ making unknown errors compliant with either spec] ( #parsing-unknown-errors ) .
88
99## Basic Usage
10+
1011``` js
1112import { ethErrors } from ' eth-json-rpc-errors'
1213
@@ -27,7 +28,7 @@ throw ethErrors.provider.unauthorized('my custom message')
2728
2829## Usage
2930
30- Installation: ` npm install eth-json-rpc-errors `
31+ Installation: ` npm install eth-json-rpc-errors ` or ` yarn add eth-json-rpc-errors `
3132
3233Import using ES6 syntax (no default export) or Node ` require ` .
3334
@@ -74,6 +75,7 @@ response.error = ethErrors.provider.custom({
7475```
7576
7677### Parsing Unknown Errors
78+
7779``` js
7880// this is useful for ensuring your errors are standardized
7981import { serializeError } from ' eth-json-rpc-errors'
@@ -82,7 +84,7 @@ import { serializeError } from 'eth-json-rpc-errors'
8284// it will be added as error.data.originalError
8385response .error = serializeError (maybeAnError)
8486
85- // you can add a custom fallback error code and message if desired
87+ // you can add a custom fallback error code and message if desired
8688const fallbackError = { code: 4999 , message: ' My custom error.' }
8789response .error = serializeError (maybeAnError, fallbackError)
8890
@@ -97,14 +99,15 @@ response.error = serializeError(maybeAnError, fallbackError)
9799```
98100
99101### Other Exports
102+
100103``` js
101104/**
102105 * TypeScript interfaces
103106 */
104107import {
105108 // these describe to the corresponding exports from index.js
106109 IEthErrors , IEthereumRpcError , IEthereumProviderError , ISerializeError ,
107- // these describe the options argument to error getters in ethErrors
110+ // these describe the options argument to error getters in ethErrors
108111 IErrorOptions , IRpcServerErrorOptions , IProviderCustomErrorOptions
109112} from ' eth-json-rpc-errors/@types'
110113
0 commit comments