Socket
Socket
Sign inDemoInstall

json-rpc-engine

Package Overview
Dependencies
Maintainers
5
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-rpc-engine - npm Package Compare versions

Comparing version 5.1.5 to 5.1.6

2

package.json
{
"name": "json-rpc-engine",
"version": "5.1.5",
"version": "5.1.6",
"description": "a tool for processing JSON RPC",

@@ -5,0 +5,0 @@ "license": "ISC",

'use strict'
const async = require('async')
const SafeEventEmitter = require('safe-event-emitter')
const { serializeError, ethErrors } = require('eth-json-rpc-errors')
const {
serializeError, EthereumRpcError, ERROR_CODES
} = require('eth-json-rpc-errors')

@@ -34,27 +36,26 @@ class RpcEngine extends SafeEventEmitter {

async _handleBatch (reqs, cb) {
const batchRes = []
for (const r of reqs) {
try {
let [err, res] = await this._promiseHandle(r)
if (!res) {
if (err) {
throw err
} else {
throw ethErrors.rpc.internal('JsonRpcEngine: Request handler returned neither error nor response.')
}
} else {
batchRes.push(res)
}
} catch (_err) {
// some kind of fatal error
return cb(_err, null)
}
// The order here is important
try {
const batchRes = await Promise.all( // 2. Wait for all requests to finish
// 1. Begin executing each request in the order received
reqs.map(this._promiseHandle.bind(this))
)
cb(null, batchRes) // 3a. Return batch response
} catch (err) {
cb(err) // 3b. Some kind of fatal error; all requests are lost
}
cb(null, batchRes)
}
_promiseHandle (req) {
return new Promise((resolve) => {
return new Promise((resolve, reject) => {
this._handle(req, (err, res) => {
resolve([err, res])
if (!res) { // defensive programming
reject(err || new EthereumRpcError(
ERROR_CODES.rpc.internal,
'JsonRpcEngine: Request handler returned neither error nor response.'
))
} else {
resolve(res)
}
})

@@ -101,3 +102,5 @@ })

const message = 'JsonRpcEngine: Response has no error or result for request:\n' + requestBody
return cb(new Error(message))
return cb(new EthereumRpcError(
ERROR_CODES.rpc.internal, message, req
))
}

@@ -107,3 +110,5 @@ if (!isComplete) {

const message = 'JsonRpcEngine: Nothing ended request:\n' + requestBody
return cb(new Error(message))
return cb(new EthereumRpcError(
ERROR_CODES.rpc.internal, message, req
))
}

@@ -110,0 +115,0 @@ // continue

@@ -1,2 +0,1 @@

const each = require('async/each')
const JsonRpcEngine = require('./index')

@@ -3,0 +2,0 @@ const asMiddleware = require('./asMiddleware')

@@ -157,6 +157,6 @@ /* eslint-env mocha */

engine.push(function (req, res, next, end) {
engine.push(function (req, res, _next, end) {
if (req.id === 4) {
delete res.result
res.error = new Error()
res.error = new Error('foobar')
return end(res.error)

@@ -163,0 +163,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc