Skip to content

Commit 352e65b

Browse files
authored
Merge pull request #5 from MetaMask/null-check
Fix faulty null checks
2 parents 702e342 + 60cec02 commit 352e65b

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eth-json-rpc-errors",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"description": "Ethereum JSON RPC and Provider errors.",
55
"main": "index.js",
66
"scripts": {

src/errors.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ module.exports = {
7777
* @returns {EthereumRpcError} The error
7878
*/
7979
server: (opts) => {
80-
if (typeof opts !== 'object' || Array.isArray(opts)) {
80+
if (!opts || typeof opts !== 'object' || Array.isArray(opts)) {
8181
throw new Error('Ethereum RPC Server errors must provide single object argument.')
8282
}
8383
const { code } = opts
@@ -203,7 +203,7 @@ module.exports = {
203203
* @returns {EthereumProviderError} The error
204204
*/
205205
custom: (opts) => {
206-
if (typeof opts !== 'object' || Array.isArray(opts)) {
206+
if (!opts || typeof opts !== 'object' || Array.isArray(opts)) {
207207
throw new Error('Ethereum Provider custom errors must provide single object argument.')
208208
}
209209
const { code, message, data } = opts
@@ -240,7 +240,7 @@ function validateOpts (opts) {
240240
if (opts) {
241241
if (typeof opts === 'string') {
242242
message = opts
243-
} else if (opts && typeof opts === 'object' && !Array.isArray(opts)) {
243+
} else if (typeof opts === 'object' && !Array.isArray(opts)) {
244244
message = opts.message
245245
data = opts.data
246246
}

src/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function serializeError (error, fallbackError = FALLBACK_ERROR) {
8383
)
8484
}
8585

86-
if (typeof error === 'object' && error instanceof EthereumRpcError) {
86+
if (error instanceof EthereumRpcError) {
8787
return error.serialize()
8888
}
8989

0 commit comments

Comments
 (0)