citolen / goproh4

Node.js module to control a GoPro Hero 4
MIT License
103 stars 24 forks source link

Rate limiting of requests required for listMedia() after cam.stop() #4

Closed hlfshell closed 9 years ago

hlfshell commented 9 years ago

I was attempting to run cam.listMedia() shortly after stopping a recording - this would result in an unhandled rejection. If the .catch() promise was handled, the error was simple "null".

After experimenting I found it had to do with timing - a simple half second delay (maybe even less?) after the cam.stop() would allow the listMedia() to fire off fine - doing listMedia() immediately after a stop() causes an error.

It might be worth noting this in the docs or introducing your own internal rate limiting.

citolen commented 9 years ago

Thank you for your feedback. Indeed when the device is busy it will return the http error code 500. I fixed it by retrying the request for a certain amount of time before throwing an error as before.

You can edit retry settings if needed.

var GoPro = require('./goproh4');
GoPro.maxRetries = 20;    //maximum retries
GoPro.retryTimeout = 100; //time between retries
...
hlfshell commented 9 years ago

Sounds good. Of note is that the 500 error was returning "null" on the catch() function, so perhaps if it fails out it needs to ensure that a real error is passed.