@matrixai/rpc
Advanced tools
Comparing version 0.5.1 to 0.6.0
@@ -48,2 +48,37 @@ "use strict"; | ||
const cleanupReason = Symbol('CleanupReason'); | ||
function composeErrorMessage(error) { | ||
switch (typeof error) { | ||
case 'boolean': | ||
case 'number': | ||
case 'string': | ||
case 'bigint': | ||
case 'symbol': | ||
return `Non-error literal ${String(error)} was thrown`; | ||
case 'object': | ||
// Let the fallback handler catch null values. | ||
if (error == null) | ||
break; | ||
// If we have an error message defined, then return that. | ||
if ('message' in error && typeof error.message === 'string') { | ||
return error.message; | ||
} | ||
// If present, mention the constructor name in the message. | ||
if (error.constructor?.name != null) { | ||
return `Non-error object ${error.constructor.name} was thrown`; | ||
} | ||
// Any other values should be handled by the fallback handler. | ||
break; | ||
} | ||
// Handle cases where the error is not serialisable, like objects created | ||
// using Object.create(null). Trying to serialise this throws a TypeError. | ||
try { | ||
return `Non-error value ${String(error)} was thrown`; | ||
} | ||
catch (e) { | ||
if (e instanceof TypeError) | ||
return 'Non-error value was thrown'; | ||
else | ||
throw e; | ||
} | ||
} | ||
let RPCServer = class RPCServer { | ||
@@ -249,3 +284,3 @@ idGen; | ||
code: -32006 /* errors.JSONRPCResponseErrorCode.RPCRemote */, | ||
message: e.message, | ||
message: composeErrorMessage(e), | ||
data: this.fromError(e), | ||
@@ -441,3 +476,3 @@ }; | ||
code: -32006 /* errors.JSONRPCResponseErrorCode.RPCRemote */, | ||
message: e.message, | ||
message: composeErrorMessage(e), | ||
data: this.fromError(e), | ||
@@ -444,0 +479,0 @@ }; |
{ | ||
"name": "@matrixai/rpc", | ||
"version": "0.5.1", | ||
"version": "0.6.0", | ||
"author": "Matrix AI", | ||
@@ -5,0 +5,0 @@ "contributors": [ |
# js-rpc | ||
staging:[![pipeline status](https://gitlab.com/MatrixAI/open-source/js-rpc/badges/staging/pipeline.svg)](https://gitlab.com/MatrixAI/open-source/js-rpc/commits/staging) | ||
master:[![pipeline status](https://gitlab.com/MatrixAI/open-source/js-rpc/badges/master/pipeline.svg)](https://gitlab.com/MatrixAI/open-source/js-rpc/commits/master) | ||
## Installation | ||
@@ -7,0 +4,0 @@ |
Sorry, the diff of this file is not supported yet
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
265565
72
3097
521
1