From 7cfdd402ca72fddd18315169440e4f847f7c9212 Mon Sep 17 00:00:00 2001 From: Deroino <117969239+Deroino@users.noreply.github.com> Date: Mon, 24 Nov 2025 08:45:50 +0800 Subject: [PATCH] =?UTF-8?q?fix(ui):=20=E4=BF=AE=E5=A4=8D=E7=A9=BA=E5=8C=85?= =?UTF-8?q?=E4=BD=93=E8=AF=B7=E6=B1=82=E6=90=BA=E5=B8=A6=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=9A=84=20Content-Type=20=E5=A4=B4=E5=AF=BC=E8=87=B4=E7=9A=84?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 之前 apiFetch 无脑调用 createHeaders(),导致 DELETE 等无包体请求也被强制加上了 Content-Type: application/json。 Fastify 服务端在收到此头时会尝试解析 Body,面对空 Body 直接抛出 FST_ERR_CTP_EMPTY_JSON_BODY 错误。 修改后:仅在 options.body 存在时才添加 JSON Content-Type 头。 --- ui/src/lib/api.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ui/src/lib/api.ts b/ui/src/lib/api.ts index b98e7874..d221ec91 100644 --- a/ui/src/lib/api.ts +++ b/ui/src/lib/api.ts @@ -75,10 +75,13 @@ class ApiClient { private async apiFetch(endpoint: string, options: RequestInit = {}): Promise { const url = `${this.baseUrl}${endpoint}`; + // Only set Content-Type if there is a body + const contentType = options.body ? 'application/json' : ''; + const config: RequestInit = { ...options, headers: { - ...this.createHeaders(), + ...this.createHeaders(contentType), ...options.headers, }, };