From 2422c7c309283761a52d4b9609f853af7d0b203e Mon Sep 17 00:00:00 2001 From: Haitao Pan Date: Thu, 5 Feb 2026 15:40:40 +0800 Subject: [PATCH] feat: enhance Vless node data fetching with robust error handling and flexible payload parsing. --- .../user-center/components/VlessQrCard.tsx | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/modules/extensions/builtin/user-center/components/VlessQrCard.tsx b/src/modules/extensions/builtin/user-center/components/VlessQrCard.tsx index 9fde1a6..758f4d6 100644 --- a/src/modules/extensions/builtin/user-center/components/VlessQrCard.tsx +++ b/src/modules/extensions/builtin/user-center/components/VlessQrCard.tsx @@ -15,7 +15,27 @@ import { VlessTransport, } from '../lib/vless' -const fetcher = (url: string) => fetch(url).then((res) => res.json()) +async function fetcher(url: string): Promise { + const res = await fetch(url, { credentials: 'include', cache: 'no-store' }) + const payload = await res.json().catch(() => null) + + if (!res.ok) { + const message = + (payload && typeof payload.message === 'string' && payload.message) || + (payload && typeof payload.error === 'string' && payload.error) || + `Request failed (${res.status})` + throw new Error(message) + } + + if (Array.isArray(payload)) { + return payload as VlessNode[] + } + if (payload && Array.isArray((payload as { nodes?: unknown }).nodes)) { + return (payload as { nodes: VlessNode[] }).nodes + } + + return [] +} export type VlessQrCopy = { label: string