[addon] check if RD cached availability response is an object

This commit is contained in:
TheBeastLT
2020-09-18 14:55:25 +02:00
parent 36ed669e1f
commit fe6f92bb31

View File

@@ -28,6 +28,13 @@ async function _getInstantAvailable(hashes, apiKey, retries = 3) {
const options = await getDefaultOptions(apiKey);
const RD = new RealDebridClient(apiKey, options);
return RD.torrents.instantAvailability(hashes)
.then(response => {
if (typeof response !== 'object') {
console.warn('RD returned non JSON response: ', response);
return uncacheProxy('moch').then(() => _getInstantAvailable(hashes, apiKey, retries - 1));
}
return response;
})
.catch(error => {
if (retries > 0 && ['ENOTFOUND', 'ETIMEDOUT'].some(v => error.message && error.message.includes(v))) {
blacklistProxy(options.proxy);