try to handle common debrid error for catalog retrieval

This commit is contained in:
TheBeastLT
2023-10-31 22:26:26 +02:00
parent 8a2f0093c6
commit 25313192d2
9 changed files with 73 additions and 23 deletions

View File

@@ -15,8 +15,8 @@ export async function getCachedStreams(streams, apiKey) {
.then(results => results.map(result => result.cachedItems))
.then(results => results.reduce((all, result) => all.concat(result), []))
.catch(error => {
if (error && error.error === 'NOAUTH') {
return Promise.reject(BadTokenError);
if (toCommonError(error)) {
return Promise.reject(error);
}
console.warn('Failed Offcloud cached torrent availability request:', error);
return undefined;
@@ -43,6 +43,7 @@ export async function getCatalog(apiKey, offset = 0) {
const options = await getDefaultOptions();
const OC = new OffcloudClient(apiKey, options);
return OC.cloud.history()
.then(torrents => torrents)
.then(torrents => (torrents || [])
.filter(torrent => torrent && statusReady(torrent))
.map(torrent => ({
@@ -137,6 +138,13 @@ async function getDefaultOptions(ip) {
return { ip, timeout: 30000 };
}
export function toCommonError(error) {
if (error?.error === 'NOAUTH' || error?.message?.startsWith('Cannot read property')) {
return BadTokenError;
}
return undefined;
}
function statusDownloading(torrent) {
return ['downloading', 'created'].includes(torrent.status);
}