rleroi / stremio-anime

Discontinued Anime add-on for Stremio
0 stars 0 forks source link

Error Handling in Stremio Add-ons #4

Closed BoredLama closed 5 years ago

BoredLama commented 5 years ago

Hi again, I noticed that this repo is not doing error handling twords Stremio.

For example these lines: https://github.com/rleroi/stremio-anime/blob/master/server.js#L122 https://github.com/rleroi/stremio-anime/blob/master/server.js#L159 https://github.com/rleroi/stremio-anime/blob/master/server.js#L185 https://github.com/rleroi/stremio-anime/blob/master/server.js#L205 https://github.com/rleroi/stremio-anime/blob/master/server.js#L211 https://github.com/rleroi/stremio-anime/blob/master/server.js#L305 https://github.com/rleroi/stremio-anime/blob/master/server.js#L384 https://github.com/rleroi/stremio-anime/blob/master/server.js#L394 https://github.com/rleroi/stremio-anime/blob/master/server.js#L454 https://github.com/rleroi/stremio-anime/blob/master/server.js#L464

All print errors locally, but no response is ever sent back to Stremio. Why is this important? Well, Stremio does http(s) requests in order to get data from add-ons, when you respond with the cb() that responds to the request. If you never use the cb(), then that request stays open until it times out, the timeouts can be extremely long for such requests so you're flooding your server with open requests.

The way the cb() works is that it takes 2 parameters, the first is the error or null, and the second is the valid response or null. While it's good to set an error (example: cb(new Error('Unknown Error'), null)), it's also enough to just respond with cb(null, null) as that also closes the request, but doesn't send an error message back. It's your choice if you want to send the error back or not, but you definitely must always use cb() to close all requests.

rleroi commented 5 years ago

Thanks a lot, I didn't know about this! I will apply this (and the episode sorting) in the next release.