From a0eccf7370b64934b7feb71186cd83f82392cb10 Mon Sep 17 00:00:00 2001 From: YuBai Date: Mon, 2 Feb 2026 11:24:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20handle()=20=E6=96=B9=E6=B3=95=20catch=20?= =?UTF-8?q?=E5=9D=97=E8=BF=94=E5=9B=9E=20undefined=20=E8=80=8C=E4=B8=8D?= =?UTF-8?q?=E6=98=AF=E9=94=99=E8=AF=AF=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当 HTTP 请求失败时,返回错误对象会导致上层代码尝试访问错误对象的属性, 造成 TypeError。改为返回 undefined 让上层代码正确处理空值情况。 --- .../douban/data/handler/DoubanAbstractLoadHandler.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/org/wanxp/douban/data/handler/DoubanAbstractLoadHandler.ts b/src/org/wanxp/douban/data/handler/DoubanAbstractLoadHandler.ts index 10e27a4..a4ac748 100644 --- a/src/org/wanxp/douban/data/handler/DoubanAbstractLoadHandler.ts +++ b/src/org/wanxp/douban/data/handler/DoubanAbstractLoadHandler.ts @@ -142,7 +142,7 @@ export default abstract class DoubanAbstractLoadHandler }else { context.syncStatusHolder?context.syncStatusHolder.syncStatus.handled(1):null; } - return e; + return undefined; }); @@ -608,12 +608,20 @@ export default abstract class DoubanAbstractLoadHandler handlePersonNameByMeta(html: CheerioAPI, movie: DoubanSubject, context: HandleContext, metaProperty:string, objectProperty:string) { + if (!movie) { + return; + } const metaProperties: string[] = html(`head > meta[property='${metaProperty}']`).get() .map((e) => { return html(e).attr('content'); }); // @ts-ignore - movie[objectProperty] + const currentArray = movie[objectProperty]; + if (!Array.isArray(currentArray)) { + return; + } + // @ts-ignore + currentArray // @ts-ignore .filter((p:Person) => p.name) // @ts-ignore