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

No default error when promise.reject() no params #58

Open
yoghurtxu opened this issue Feb 7, 2024 · 0 comments
Open

No default error when promise.reject() no params #58

yoghurtxu opened this issue Feb 7, 2024 · 0 comments

Comments

@yoghurtxu
Copy link

Hi,
the await-to-js readme does not mention the different between using method 1(try catch) and method 2(await-to-js).
but their use in reject is different.

For example:

function returnPromise() {
    return Promise.reject();
}

1.when use try catch:

try {
   const res = await this.returnPromise();
   console.log("res", res);
   console.log("first case normal process");
 } catch (err) {
   console.log("err", err);
   console.log("first case abnormal process");
 }

err is undefined,but "first case abnormal process" can output normally.

2.when use await-to-js

const [err, res] = await to(this.returnPromise());
 if (res) {
   console.log("res", res);
   console.log("second case normal process");
 } else if (err) {
   console.log("err", err);
   console.log("second case abnormal process");
}

err is undefined, so "second case abnormal process" cannot output normally.

Expect:

if await-to-js error is undefined, return default error(new Error() or other).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant