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

Throw an Error in async functions instead of returning an object #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

besdar
Copy link

@besdar besdar commented Aug 28, 2024

Hello @s0ftik3!

I noticed that in the asynchronous methods of the Reverso class, you return objects instead of throwing an error. As a result, the returned promise is resolved with an object that indicates an error occurred. In the event of an error in your code, it is better to throw an instance of the Error class.

After my changes it would be possible to use catch method of the Promise class, for example:

reverso.getContext(
    'meet me half way',
    'english',
    'russian',
).then(result => doMyStuff(result)).catch(err => handleError(err))

ref: https://javascript.info/async-await

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

Successfully merging this pull request may close these issues.

1 participant