Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json-rpc-engine

Package Overview
Dependencies
Maintainers
2
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 3.8.0 to 4.0.0

2

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

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -42,2 +42,11 @@ 'use strict'

this._runMiddleware(req, res, (err) => {
// take a clear any responseError
const responseError = res._originalError
delete res._originalError
if (responseError) {
// ensure no result is present on an errored response
delete res.result
// return originalError and response
return cb(responseError, res)
}
// return response

@@ -100,3 +109,7 @@ cb(err, res)

function end (err) {
if (err) return cb(err)
// if errored, set the error but dont pass to callback
if (err) {
res.error = serializeError(err)
res._originalError = err
}
// mark as completed

@@ -110,8 +123,6 @@ isComplete = true

function completeRequest (err) {
// this is an internal catastrophic error, not an error from middleware
if (err) {
// prepare error message
res.error = {
code: err.code || -32603,
message: err.stack,
}
res.error = serializeError(err)
// return error-first and res with err

@@ -131,2 +142,9 @@ return onDone(err, res)

function serializeError(err) {
return {
code: err.code || -32603,
message: err.stack,
}
}
module.exports = RpcEngine

@@ -213,2 +213,28 @@ /* eslint-env mocha */

})
it('calls back next handler even if error', function (done) {
let engine = new RpcEngine()
let sawNextReturnHandlerCalled = false
engine.push(function (req, res, next, end) {
next(function (cb) {
sawNextReturnHandlerCalled = true
cb()
})
})
engine.push(function(req, res, next, end) {
end(new Error('boom'))
})
let payload = { id: 1, jsonrpc: '2.0', method: 'hello' }
engine.handle(payload, (err, res) => {
assert(err, 'did error')
assert(sawNextReturnHandlerCalled, 'saw next return handler called')
done()
})
})
})
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