diff --git a/src/source/Source.ts b/src/source/Source.ts index 71dd54f..8276f1b 100644 --- a/src/source/Source.ts +++ b/src/source/Source.ts @@ -1,5 +1,6 @@ import TTLCache from '@isaacs/ttlcache'; import { ContentType } from 'stremio-addon-sdk'; +import { NotFoundError } from '../error'; import { Context, CountryCode } from '../types'; import { Id } from '../utils'; @@ -35,7 +36,17 @@ export abstract class Source { return this.sourceResultCache.get(id.id) as SourceResult[]; } - const sourceResults = await this.handleInternal(ctx, type, id); + let sourceResults: SourceResult[]; + try { + sourceResults = await this.handleInternal(ctx, type, id); + } catch (error) { + if (error instanceof NotFoundError) { + sourceResults = []; + } else { + throw error; + } + } + this.sourceResultCache.set(id.id, sourceResults); return sourceResults; diff --git a/src/utils/Fetcher.ts b/src/utils/Fetcher.ts index 499c83a..5396b70 100644 --- a/src/utils/Fetcher.ts +++ b/src/utils/Fetcher.ts @@ -192,7 +192,7 @@ export class Fetcher { } private determineCacheTtl(status: number, policy: CachePolicy, init?: CustomRequestInit): number { - if (status === 200) { + if (status === 200 || status === 404) { return Math.max(policy.timeToLive(), init?.minCacheTtl ?? this.MIN_CACHE_TTL); } diff --git a/src/utils/StreamResolver.ts b/src/utils/StreamResolver.ts index 8d64e51..75797c7 100644 --- a/src/utils/StreamResolver.ts +++ b/src/utils/StreamResolver.ts @@ -1,7 +1,7 @@ import bytes from 'bytes'; import { ContentType, Stream } from 'stremio-addon-sdk'; import winston from 'winston'; -import { logErrorAndReturnNiceString, NotFoundError } from '../error'; +import { logErrorAndReturnNiceString } from '../error'; import { ExtractorRegistry } from '../extractor'; import { Source } from '../source'; import { Context, Format, UrlResult } from '../types'; @@ -56,10 +56,6 @@ export class StreamResolver { urlResults.push(...sourceUrlResults.flat()); } catch (error) { - if (error instanceof NotFoundError) { - return; - } - sourceErrorOccurred = true; if (showErrors(ctx.config)) {