Skip to content

Commit

Permalink
Merge pull request #5 from MetaMask/null-check
Browse files Browse the repository at this point in the history
Fix faulty null checks
  • Loading branch information
danfinlay authored Feb 12, 2020
2 parents 702e342 + 60cec02 commit 352e65b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eth-json-rpc-errors",
"version": "2.0.1",
"version": "2.0.2",
"description": "Ethereum JSON RPC and Provider errors.",
"main": "index.js",
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions src/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ module.exports = {
* @returns {EthereumRpcError} The error
*/
server: (opts) => {
if (typeof opts !== 'object' || Array.isArray(opts)) {
if (!opts || typeof opts !== 'object' || Array.isArray(opts)) {
throw new Error('Ethereum RPC Server errors must provide single object argument.')
}
const { code } = opts
Expand Down Expand Up @@ -203,7 +203,7 @@ module.exports = {
* @returns {EthereumProviderError} The error
*/
custom: (opts) => {
if (typeof opts !== 'object' || Array.isArray(opts)) {
if (!opts || typeof opts !== 'object' || Array.isArray(opts)) {
throw new Error('Ethereum Provider custom errors must provide single object argument.')
}
const { code, message, data } = opts
Expand Down Expand Up @@ -240,7 +240,7 @@ function validateOpts (opts) {
if (opts) {
if (typeof opts === 'string') {
message = opts
} else if (opts && typeof opts === 'object' && !Array.isArray(opts)) {
} else if (typeof opts === 'object' && !Array.isArray(opts)) {
message = opts.message
data = opts.data
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function serializeError (error, fallbackError = FALLBACK_ERROR) {
)
}

if (typeof error === 'object' && error instanceof EthereumRpcError) {
if (error instanceof EthereumRpcError) {
return error.serialize()
}

Expand Down

0 comments on commit 352e65b

Please sign in to comment.