n0mad01 / node.bittrex.api

No longer maintained
MIT License
183 stars 187 forks source link

Questions: How to correctly handle errors #31

Closed groentebroer closed 7 years ago

groentebroer commented 7 years ago

Hi,

I am trying to implement your module, which speeds things up greatly!

What I am trying to solve is to correctly handle errors when it might occur. Two scenario's I can think of:

  1. HTTP errors (timeout, HTTP 500, 403, etc.)
  2. Json errors (success: false)

Looking at the code and samples, it is not clear to me how the codes responds on those errors, or is this not part of the implementation yet?

Most frameworks I know work, with the "err" param being the first result on the callback, but this not seem to be implemented here.

Can you give an error handling example? For example on:

bittrex.getbalance({ currency : 'BTC' }, function( data ) { console.log( data ); });

If not implemented yet, is it somewhere on the roadmap (soon)? Based on that, some retry mecanism may be build inside this module of on top of this to for example retry a buy or sell if an error occurs.

dparlevliet commented 7 years ago

I had the same complaints. I think right now the only way to resolve it would be to use try/catch but if memory serves that wasn't always true because some of the errors were caught but not forwarded.

Personally, I ended up downloading the project and modifying it to provide the err param as the first param for all functions. I did not submit a pull request because it would be a breaking change. It could be possible to make this change in a non-breaking way if we go against standards and have the err param as the second param provided for all functions.

I'm willing to submit a PR if needed. Just tag me with a decision.

n0mad01 commented 7 years ago

i was struggling which would be the best approach but it seems @dparlevliet has already an answer. if you can submit a pull request that would be great!

n0mad01 commented 7 years ago

@dparlevliet great stuff again, thanks one more time! i've released it to a new version 0.4 and also mentioned you in the README once more ;)

dparlevliet commented 7 years ago

any time

n0mad01 commented 7 years ago

thanks!