json-rpc-engine
Advanced tools
Comparing version 3.8.0 to 4.0.0
{ | ||
"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() | ||
}) | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29140
810
1