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

@@ -14,11 +14,8 @@ export async function getCachedStreams(streams, apiKey) {
const hashes = streams.map(stream => stream.infoHash);
const available = await AD.magnet.instant(hashes)
.catch(error => {
if (error && error.code === 'AUTH_BAD_APIKEY') {
return Promise.reject(BadTokenError);
}
if (error && error.code === 'AUTH_USER_BANNED') {
return Promise.reject(AccessDeniedError);
if (toCommonError(error)) {
return Promise.reject(error);
}
console.warn(`Failed AllDebrid cached [${hashes[0]}] torrent availability request:`, error);
return undefined;
@@ -166,6 +163,16 @@ async function getDefaultOptions(ip) {
return { base_agent: AGENT, timeout: 30000 };
}
export function toCommonError(error) {
if (error && error.code === 'AUTH_BAD_APIKEY') {
return BadTokenError;
}
if (error && error.code === 'AUTH_USER_BANNED') {
return AccessDeniedError;
}
return undefined;
}
function statusError(statusCode) {
return [5, 6, 7, 8, 9, 10, 11].includes(statusCode);
}