hubiinetwork / nahmii-sdk

Javascript SDK for using the hubii nahmii APIs
http://hubii.com
GNU Lesser General Public License v3.0
8 stars 0 forks source link

Unhandled promise rejection fetching API access token #67

Closed liamaharon closed 5 years ago

liamaharon commented 5 years ago

It appears on ln 96 in nahmii-provider.js, Promise.reject is thrown and not caught anywhere within the SDK.

The function throwing Promise.reject is initiated from a call to the NahmiiProvider.getApiAccessToken method.

When this method is called manually by the user, the error can be caught by wrapping the call in a try catch statement, which is fine.

The issue I'm experiencing is that on initialization, NahmiiProvider instances are set to automatically call this method every minute. If there's a network error, the error will be thrown and I can't find a way to handle it.

Not sure if there's an obvious way to catch this that I'm missing, but until I do find a solution it'll be an issue in the hubii core project which is currently configured to loudly complain if there're any unhandled errors.

A simple fix is just to return the error instead of throwing via Promise.reject, but not sure if that's the cleanest solution, or if there's a way to catch this outside of the SDK.

Any input would be appreciated @morfj

Thanks

morfj commented 5 years ago

I think that could be removed. Logging it (line95) is probably all we need to do since it will try again in a while.

liamaharon commented 5 years ago

Cool, I'll open a PR