From cd59d60ef678d6be5c80852ef70bcf9452991ddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Cie=C5=9Blak?= Date: Thu, 20 Jun 2024 11:52:41 +0200 Subject: [PATCH] MockedUnaryCall.then: Handle onrejected not being defined I just copied stuff from the linked implementation of then. --- .../teleterm/src/services/tshd/cloneableClient.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/web/packages/teleterm/src/services/tshd/cloneableClient.ts b/web/packages/teleterm/src/services/tshd/cloneableClient.ts index 8e2065e23d9ba..68420b0fe2bfe 100644 --- a/web/packages/teleterm/src/services/tshd/cloneableClient.ts +++ b/web/packages/teleterm/src/services/tshd/cloneableClient.ts @@ -404,9 +404,17 @@ export class MockedUnaryCall onrejected?: (reason: any) => TResult2 | PromiseLike ): Promise { if (this.error) { - // Despite this being an error branch, it needs to use Promise.resolve. Otherwise we'd get - // uncaught errors. See https://www.promisejs.org/implementing/#then - return Promise.resolve(onrejected(this.error)); + if (typeof onrejected === 'function') { + try { + // Despite this being an error branch, it needs to use Promise.resolve. Otherwise we'd get + // uncaught errors. See https://www.promisejs.org/implementing/#then + return Promise.resolve(onrejected(this.error)); + } catch (ex) { + return Promise.reject(ex); + } + } else { + return Promise.reject(this.error); + } } return Promise.resolve(