@stinkycomputing/sesame-api-client 1.4.1-beta.2 → 1.4.1-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -22226,10 +22226,33 @@ var RPCClient = class extends EventEmitter {
22226
22226
  this.connection.on("rpc", (data) => this.messageHandler(data));
22227
22227
  this.connection.on("error", this.errorHandler);
22228
22228
  this.options = options;
22229
- this.service = service.create(this.rpcImpl);
22229
+ this.service = this.wrapServicePromises(service.create(this.rpcImpl));
22230
22230
  this.eventTypes = options.eventTypes || {};
22231
22231
  this.sendTimeout = options.sendTimeout || 5 * 1e3;
22232
22232
  }
22233
+ /**
22234
+ * Wraps service method calls to attach a rejection handler on all returned
22235
+ * promises. This prevents unhandled promise rejections (e.g. from timeouts
22236
+ * while disconnected) from crashing the host process. Callers can still
22237
+ * catch errors normally via await / .catch().
22238
+ */
22239
+ wrapServicePromises(service) {
22240
+ const self = this;
22241
+ return new Proxy(service, {
22242
+ get(target, prop) {
22243
+ const value = target[prop];
22244
+ if (typeof value !== "function") return value;
22245
+ return function(...args) {
22246
+ const result = value.apply(target, args);
22247
+ if (result != null && typeof result.catch === "function") {
22248
+ result.catch(() => {
22249
+ });
22250
+ }
22251
+ return result;
22252
+ };
22253
+ }
22254
+ });
22255
+ }
22233
22256
  async flushMessageBuffer() {
22234
22257
  const messages = [];
22235
22258
  for (const seq in this.messageBuffer) {