add limits exceeded error handling for PM and RD

This commit is contained in:
TheBeastLT 2024-11-26 12:47:48 +02:00
parent 694bc56029
commit 0b64acb5fd
3 changed files with 26 additions and 9 deletions

View file

@ -46,7 +46,7 @@ builder.defineCatalogHandler((args) => {
cacheMaxAge: CATALOG_CACHE_MAX_AGE cacheMaxAge: CATALOG_CACHE_MAX_AGE
})) }))
.catch(error => { .catch(error => {
return Promise.reject(`Failed retrieving catalog ${args.id}: ${JSON.stringify(error)}`); return Promise.reject(`Failed retrieving catalog ${args.id}: ${JSON.stringify(error.message || error)}`);
}); });
}) })

View file

@ -95,7 +95,7 @@ export async function resolve({ ip, isBrowser, apiKey, infoHash, cachedEntryInfo
return _getCachedLink(PM, infoHash, cachedEntryInfo, fileIndex, ip, isBrowser) return _getCachedLink(PM, infoHash, cachedEntryInfo, fileIndex, ip, isBrowser)
.catch(() => _resolve(PM, infoHash, cachedEntryInfo, fileIndex, ip, isBrowser)) .catch(() => _resolve(PM, infoHash, cachedEntryInfo, fileIndex, ip, isBrowser))
.catch(error => { .catch(error => {
if (error?.message?.includes('Account not premium.')) { if (isAccessDeniedError(error)) {
console.log(`Access denied to Premiumize ${infoHash} [${fileIndex}]`); console.log(`Access denied to Premiumize ${infoHash} [${fileIndex}]`);
return StaticResponse.FAILED_ACCESS; return StaticResponse.FAILED_ACCESS;
} }
@ -187,6 +187,15 @@ function statusReady(status) {
return ['finished', 'seeding'].includes(status); return ['finished', 'seeding'].includes(status);
} }
function isAccessDeniedError(error) {
return ['Account not premium.'].some(value => error?.message?.includes(value));
}
function isLimitExceededError(error) {
return ['Fair use limit reached!', 'You already have a maximum of 25 active downloads in progress!']
.some(value => error?.message?.includes(value));
}
async function getDefaultOptions(ip) { async function getDefaultOptions(ip) {
return { timeout: 5000 }; return { timeout: 5000 };
} }

View file

@ -120,14 +120,18 @@ export async function resolve({ ip, isBrowser, apiKey, infoHash, fileIndex }) {
return _resolve(RD, infoHash, fileIndex, isBrowser) return _resolve(RD, infoHash, fileIndex, isBrowser)
.catch(error => { .catch(error => {
if (accessDeniedError(error)) { if (isAccessDeniedError(error)) {
console.log(`Access denied to RealDebrid ${infoHash} [${fileIndex}]`); console.log(`Access denied to RealDebrid ${infoHash} [${fileIndex}]`);
return StaticResponse.FAILED_ACCESS; return StaticResponse.FAILED_ACCESS;
} }
if (infringingFile(error)) { if (isInfringingFileError(error)) {
console.log(`Infringing file removed from RealDebrid ${infoHash} [${fileIndex}]`); console.log(`Infringing file removed from RealDebrid ${infoHash} [${fileIndex}]`);
return StaticResponse.FAILED_INFRINGEMENT; return StaticResponse.FAILED_INFRINGEMENT;
} }
if (isLimitExceededError(error)) {
console.log(`Limits exceeded in RealDebrid ${infoHash} [${fileIndex}]`);
return StaticResponse.LIMITS_EXCEEDED;
}
return Promise.reject(`Failed RealDebrid adding torrent ${JSON.stringify(error)}`); return Promise.reject(`Failed RealDebrid adding torrent ${JSON.stringify(error)}`);
}); });
} }
@ -307,7 +311,7 @@ export function toCommonError(error) {
if (error && error.code === 8) { if (error && error.code === 8) {
return BadTokenError; return BadTokenError;
} }
if (error && accessDeniedError(error)) { if (error && isAccessDeniedError(error)) {
return AccessDeniedError; return AccessDeniedError;
} }
return undefined; return undefined;
@ -337,12 +341,16 @@ function statusReady(status) {
return ['downloaded', 'dead'].includes(status); return ['downloaded', 'dead'].includes(status);
} }
function accessDeniedError(error) { function isAccessDeniedError(error) {
return [9, 20].includes(error?.code); return [8, 9, 20].includes(error?.code);
} }
function infringingFile(error) { function isInfringingFileError(error) {
return error && error.code === 35; return [35].includes(error?.code);
}
function isLimitExceededError(error) {
return [21, 23, 26, 29, 36].includes(error?.code);
} }
async function getDefaultOptions(ip) { async function getDefaultOptions(ip) {