Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v15] MockedUnaryCall.then: Handle onrejected not being defined #43269

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions web/packages/teleterm/src/services/tshd/cloneableClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,17 @@ export class MockedUnaryCall<Response extends object>
onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>
): Promise<TResult1 | TResult2> {
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));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh actually, it makes total sense that this needs to be Promise.resolve(onrejected(…)).

If you have something like this:

Promise.reject().then(() => { /* onfulfilled */ }, () => { /* onrejected */)

and onrejected doesn't reject itself, the final promise you get is fulfilled, not rejected.

} catch (ex) {
return Promise.reject(ex);
}
} else {
return Promise.reject(this.error);
}
}

return Promise.resolve(
Expand Down
Loading