Socket
Socket
Sign inDemoInstall

jsonbird

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonbird - npm Package Compare versions

Comparing version 1.1.1 to 2.0.0

lib/RPCError.js

43

lib/JSONBird.js

@@ -667,3 +667,3 @@ 'use strict';

if (name.startsWith('rpc.')) { // reserved
throw new RPCRequestError('Method not found', -32601);
throw new RPCRequestError(Error('Method not found'), -32601);
}

@@ -693,3 +693,3 @@

throw new RPCRequestError('Method not found', -32601);
throw new RPCRequestError(Error('Method not found'), -32601);
}))

@@ -783,3 +783,3 @@ .finally(() => {

if (clientPendingMap.has(id)) {
return Promise.reject(new RPCRequestError('Generated request "id" is not unique!', -32603));
return Promise.reject(new RPCRequestError(Error('Generated request "id" is not unique!'), -32603));
}

@@ -791,3 +791,3 @@

const timer = timeout && setTimeout(
() => reject(new RPCRequestError(`Remote Call timed out after ${timeout}ms`, -32000)),
() => reject(new RPCRequestError(Error(`Remote Call timed out after ${timeout}ms`), -32000)),
timeout

@@ -1006,3 +1006,3 @@ );

return Promise.reject(new RPCRequestError(
`Error parsing your JSON string: ${err.message}`,
Error(`Error parsing your JSON string: ${err.message}`),
-32700

@@ -1035,3 +1035,3 @@ ))

return Promise.reject(new RPCRequestError(
`Error parsing your JSON string: ${err.message}`,
Error(`Error parsing your JSON string: ${err.message}`),
-32700

@@ -1085,4 +1085,4 @@ ))

return Promise.reject(new RPCRequestError(
'Unable to determine if the message was a request or response object (one of the "method", "result"' +
' or "error" properties must be present)',
Error('Unable to determine if the message was a request or response object (one of the "method", "result"' +
' or "error" properties must be present)'),
-32600

@@ -1111,11 +1111,13 @@ ));

if (!('jsonrpc' in object)) {
throw new RPCRequestError('Invalid Request: "jsonrpc" attribute is missing (JSON-RPC version 1 is not supported)', -32600);
throw new RPCRequestError(Error(
'Invalid Request: "jsonrpc" attribute is missing (JSON-RPC version 1 is not supported)'
), -32600);
}
if (!JSONBird.isValidVersion(object.jsonrpc)) {
throw new RPCRequestError('Invalid Request: given "jsonrpc" version is not supported', -32600);
throw new RPCRequestError(Error('Invalid Request: given "jsonrpc" version is not supported'), -32600);
}
if (!JSONBird.isValidMethodName(object.method)) {
throw new RPCRequestError('Method not found: "method" attribute must be a string', -32601);
throw new RPCRequestError(Error('Method not found: "method" attribute must be a string'), -32601);
}

@@ -1132,3 +1134,3 @@

else {
throw new RPCRequestError('Invalid Request: "params" must be an array or object', -32600);
throw new RPCRequestError(Error('Invalid Request: "params" must be an array or object'), -32600);
}

@@ -1139,3 +1141,3 @@ }

if (id === null) {
throw new RPCRequestError('Invalid Request: "id" must be a number or a string', -32600);
throw new RPCRequestError(Error('Invalid Request: "id" must be a number or a string'), -32600);
}

@@ -1170,15 +1172,15 @@

// emitted as an 'error' event
throw new RPCResponseError('Invalid Response: "jsonrpc" property must be "2.0"');
throw new RPCResponseError(Error('Invalid Response: "jsonrpc" property must be "2.0"'));
}
if (!JSONBird.isValidID(object.id)) {
throw new RPCResponseError('Invalid Response: "id" property must be a number or string');
throw new RPCResponseError(Error('Invalid Response: "id" property must be a number or string'));
}
if (!('result' in object || typeof object.error === 'object')) {
throw new RPCResponseError('Invalid Response: Must have a "error" or an "result" property');
throw new RPCResponseError(Error('Invalid Response: Must have a "error" or an "result" property'));
}
if ('result' in object && 'error' in object) {
throw new RPCResponseError('Invalid Response: The "error" and "result" properties are both present');
throw new RPCResponseError(Error('Invalid Response: The "error" and "result" properties are both present'));
}

@@ -1190,3 +1192,3 @@

if (!pendingEntry) {
throw new RPCResponseError('Invalid Response: Unknown id');
throw new RPCResponseError(Error('Invalid Response: Unknown id'));
}

@@ -1198,3 +1200,3 @@

else /* if ('error' in object) */ {
const error = new RPCRequestError(object.error.message, object.error.code, object.error.data);
const error = new RPCRequestError(Error(object.error.message), object.error.code, object.error.data);

@@ -1247,4 +1249,5 @@ if (this.receiveErrorStack && object.error.data && object.error.data.isJSError === true) {

JSONBird.RPCError = RPCRequestError;
JSONBird.RPCRequestError = RPCRequestError;
JSONBird.RPCResponseError = RPCResponseError;
module.exports = JSONBird;
'use strict';
class RPCRequestError extends Error {
const RPCError = require('./RPCError');
class RPCRequestError extends RPCError {
static defaultErrorMessage(code) {

@@ -36,7 +38,11 @@ if (code === -32700) {

constructor(messageArg, codeArg = 0, data = undefined) {
constructor(wrapped, codeArg = 0, data = undefined) {
super(wrapped);
const code = Number(codeArg) || 0;
const message = String(messageArg || '') || RPCRequestError.defaultErrorMessage(code);
super(message);
if (!this.message) {
this.message = RPCRequestError.defaultErrorMessage(code);
}
this.name = 'RPCRequestError';

@@ -43,0 +49,0 @@ this.code = code;

'use strict';
class RPCResponseError extends Error {
constructor(message) {
super(message);
const RPCError = require('./RPCError');
class RPCResponseError extends RPCError {
constructor(wrapped) {
super(wrapped);
this.name = 'RPCResponseError';

@@ -7,0 +10,0 @@ }

{
"name": "jsonbird",
"version": "1.1.1",
"version": "2.0.0",
"description": "JSON-RPC 2.0 client/server/peer for any reliable transport. Inter-process communication. REST. WebSocket. WebWorker. Out of order messaging or in-order byte streams",

@@ -5,0 +5,0 @@ "main": "lib/JSONBird.js",

@@ -20,3 +20,3 @@ /* eslint prefer-rest-params: 'off' */

function myTestFunction() {
return new RPCRequestError('Hello!');
return new RPCRequestError(Error('Hello!'));
}

@@ -26,2 +26,3 @@

assert.instanceOf(error, Error);
assert.instanceOf(error, RPCRequestError);
assert.strictEqual(error.name, 'RPCRequestError');

@@ -34,17 +35,20 @@ assert.strictEqual(error.message, 'Hello!');

assert.isUndefined(error.data);
assert.isString(error.toString());
assert.include(error.toString(), 'RPCRequestError');
assert.include(error.toString(), 'Hello!');
const error2 = new RPCRequestError('Hello!', 1234, {foo: [{bar: 'baz'}]});
const error2 = new RPCRequestError(Error('Hello!'), 1234, {foo: [{bar: 'baz'}]});
assert.strictEqual(error2.code, 1234);
assert.deepEqual(error2.data, {foo: [{bar: 'baz'}]});
assert.match((new RPCRequestError('', -32700)).message, /parse error/i);
assert.match((new RPCRequestError('', -32600)).message, /invalid request/i);
assert.match((new RPCRequestError('', -32601)).message, /method not found/i);
assert.match((new RPCRequestError('', -32602)).message, /invalid params/i);
assert.match((new RPCRequestError('', -32603)).message, /internal error/i);
assert.match((new RPCRequestError('', -32000)).message, /timed out/i);
assert.match((new RPCRequestError('', -32099)).message, /server error/i);
assert.match((new RPCRequestError('', -32050)).message, /server error/i);
assert.match((new RPCRequestError('', -32001)).message, /server error/i);
assert.strictEqual((new RPCRequestError('', 123)).message, '');
assert.match((new RPCRequestError(Error(''), -32700)).message, /parse error/i);
assert.match((new RPCRequestError(Error(''), -32600)).message, /invalid request/i);
assert.match((new RPCRequestError(Error(''), -32601)).message, /method not found/i);
assert.match((new RPCRequestError(Error(''), -32602)).message, /invalid params/i);
assert.match((new RPCRequestError(Error(''), -32603)).message, /internal error/i);
assert.match((new RPCRequestError(Error(''), -32000)).message, /timed out/i);
assert.match((new RPCRequestError(Error(''), -32099)).message, /server error/i);
assert.match((new RPCRequestError(Error(''), -32050)).message, /server error/i);
assert.match((new RPCRequestError(Error(''), -32001)).message, /server error/i);
assert.strictEqual((new RPCRequestError(Error(''), 123)).message, '');
});

@@ -369,2 +373,3 @@ });

assert.instanceOf(error, RPCRequestError);
assert.instanceOf(error, Error);
assert.strictEqual(error.name, 'RPCRequestError');

@@ -417,2 +422,3 @@ assert.strictEqual(error.code, -32601);

assert.instanceOf(error, RPCRequestError);
assert.instanceOf(error, Error);
assert.strictEqual(error.name, 'RPCRequestError');

@@ -419,0 +425,0 @@ assert.strictEqual(error.code, -32601);

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