Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(client): 不新增服务端错误正文日志

liugaowei8d5086317155
diff --git a/apps/desktop/src/main/authManager.ts b/apps/desktop/src/main/authManager.ts
index b13a561b9b..2384fa5d94 100644
--- a/apps/desktop/src/main/authManager.ts
+++ b/apps/desktop/src/main/authManager.ts
@@ -2304,10 +2304,6 @@ async function apiFetch<T>(
return { ok: false, status: response.status, data: null as T, retryAt };
}
const errorCode = (data as AuthErrorResponse | null)?.error?.code;
- if (!response.ok) {
- log.warn('auth response rejected', apiPath, { status: response.status },
- requestErrorMessage((data as AuthErrorResponse | null)?.error));
- }
if (response.status === 401 && errorCode === 'ACCOUNT_UNAVAILABLE' && currentUser) {
// Internal auth-server calls (profile/feature flags/refresh) do not pass
// through serverApiClient, but share the same terminal auth contract.
diff --git a/apps/desktop/src/main/ossPublicUpload.ts b/apps/desktop/src/main/ossPublicUpload.ts
index 5b2f9215ff..ce3d1aa529 100644
--- a/apps/desktop/src/main/ossPublicUpload.ts
+++ b/apps/desktop/src/main/ossPublicUpload.ts
@@ -120,7 +120,6 @@ export async function uploadPublicAsset(
try {
const data = (await response.json()) as { error?: { code?: string } } | null;
code = data?.error?.code;
- logError('presign', data?.error);
} catch (error) {
logError('presign', error);
// 非 JSON 错误体,只保留 status
diff --git a/apps/mobile/src/__tests__/apiClient.test.ts b/apps/mobile/src/__tests__/apiClient.test.ts
index 85be592213..151764c574 100644
--- a/apps/mobile/src/__tests__/apiClient.test.ts
+++ b/apps/mobile/src/__tests__/apiClient.test.ts
@@ -194,8 +194,7 @@ describe('apiFetchRaw', () => {
message: 'remote disabled',
details: { reason: 'private server details' },
});
- expect(logs.join('')).toContain('remote disabled');
- expect(logs.join('')).not.toContain('private server details');
+ expect(logs).toEqual([]);
});
it('notifies the terminal auth boundary for ACCOUNT_UNAVAILABLE', async () => {
diff --git a/apps/mobile/src/api/client.ts b/apps/mobile/src/api/client.ts
index 71f719817d..d9cdba84bc 100644
--- a/apps/mobile/src/api/client.ts
+++ b/apps/mobile/src/api/client.ts
@@ -129,8 +129,6 @@ export async function apiFetchRaw<T>(
if (!response.ok) {
const error = readError(data);
const code = error.code ?? `HTTP_${response.status}`;
- const failure = new ApiError(code, response.status, error.message ?? i18n.t('apiErrors.requestFailed'), error.details);
- mobileDebugLog('warn', 'network', 'response rejected', { status: response.status, code }, failure.message);
if (response.status === 401 && code === 'ACCOUNT_UNAVAILABLE') {
try {
await accountUnavailableHandler?.();
@@ -138,7 +136,7 @@ export async function apiFetchRaw<T>(
// Preserve the original typed API error even if local cleanup fails.
}
}
- throw failure;
+ throw new ApiError(code, response.status, error.message ?? i18n.t('apiErrors.requestFailed'), error.details);
}
return data as T;
diff --git a/packages/auth-client/src/__tests__/client.test.ts b/packages/auth-client/src/__tests__/client.test.ts
index 3bf4d4969c..015aacb0c4 100644
--- a/packages/auth-client/src/__tests__/client.test.ts
+++ b/packages/auth-client/src/__tests__/client.test.ts
@@ -52,21 +52,35 @@ describe("CindyAuthClient", () => {
);
});
- it("keeps server error messages and ignores a failing error logger", async () => {
+ it("ignores a failing error logger without changing the mapped request error", async () => {
const onRequestError = vi.fn(() => { throw new Error("logger unavailable"); });
+ const original = new TypeError("proxy refused tunnel");
const instance = new CindyAuthClient({
baseUrl: "https://auth.example.com", region: "cn", deviceId: "device-1", clientType: "desktop",
- fetch: async () => response(401, { error: { code: "INVALID_REFRESH_TOKEN", message: "Refresh token was revoked" } }),
+ fetch: async () => { throw original; },
onRequestError,
});
await expect(instance.refresh("unused-token")).rejects.toMatchObject({
- code: "INVALID_REFRESH_TOKEN", message: "Refresh token was revoked",
+ code: "NETWORK_ERROR",
});
expect(onRequestError).toHaveBeenCalledExactlyOnceWith(
- "/api/auth/refresh", 401, expect.objectContaining({ message: "Refresh token was revoked" }),
+ "/api/auth/refresh", 0, original,
);
});
+ it("returns parsed HTTP error text to the caller without sending it to the exception logger", async () => {
+ const onRequestError = vi.fn();
+ const instance = new CindyAuthClient({
+ baseUrl: "https://auth.example.com", region: "cn", deviceId: "device-1", clientType: "desktop",
+ fetch: async () => response(400, { error: { code: "INVALID_PARAMS", message: "private display name rejected" } }),
+ onRequestError,
+ });
+ await expect(instance.refresh("unused-token")).rejects.toMatchObject({
+ code: "INVALID_PARAMS", message: "private display name rejected",
+ });
+ expect(onRequestError).not.toHaveBeenCalled();
+ });
+
it.each([
["120", 120_000],
["Wed, 07 Oct 2026 06:02:00 GMT", 120_000],
diff --git a/packages/auth-client/src/client.ts b/packages/auth-client/src/client.ts
index d602a988b7..0e77883e5c 100644
--- a/packages/auth-client/src/client.ts
+++ b/packages/auth-client/src/client.ts
@@ -580,9 +580,7 @@ export class CindyAuthClient {
parsed.data.message ??
"Authentication request failed")
: "Authentication request failed";
- const error = new AuthApiError(code, response.status, message, retryAt);
- this.logRequestError(path, response.status, error);
- throw error;
+ throw new AuthApiError(code, response.status, message, retryAt);
}
const parsed = schema.safeParse(data);
if (!parsed.success) {