Skip to content

Commit df618c0

Browse files
awesomeYGawesomeYG
andauthored
Feat/v0.11.1 (#55)
* chore: update @ctzhian/tiptap to version 1.8.2 and refactor error handling in HttpClient - Updated the @ctzhian/tiptap dependency from 1.8.0 to 1.8.2. - Removed the retry mechanism from the HttpClient request handling. - Enhanced error message translation for better user feedback. - Adjusted header component logic to display the ForumSelector based on forum count. * chore: update @ctzhian/tiptap to version 1.8.2 in package.json and pnpm-lock.yaml --------- Co-authored-by: awesomeYG <gang.yang@chaitin.com>
1 parent b0c3496 commit df618c0

File tree

6 files changed

+32
-33
lines changed

6 files changed

+32
-33
lines changed

ui/admin/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
"dependencies": {
1515
"@ctzhian/modelkit": "^2.4.0",
16-
"@ctzhian/tiptap": "^1.8.0",
16+
"@ctzhian/tiptap": "^1.8.2",
1717
"@ctzhian/ui": "^7.0.5",
1818
"@dnd-kit/core": "^6.3.1",
1919
"@dnd-kit/sortable": "^10.0.0",

ui/admin/pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/front/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"icon": "node ./script/downLoadIcon.js"
1616
},
1717
"dependencies": {
18-
"@ctzhian/tiptap": "^1.8.0",
18+
"@ctzhian/tiptap": "^1.8.2",
1919
"@ctzhian/ui": "^7.0.5",
2020
"@emotion/cache": "^11.14.0",
2121
"@emotion/react": "^11.14.0",

ui/front/pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/front/src/api/httpClient.ts

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
import alert from "@/components/alert";
14-
import { clearCache, generateCacheKey, retryRequest } from "@/lib/api-cache";
14+
import { clearCache, generateCacheKey } from "@/lib/api-cache";
1515
import { API_CONSTANTS } from "@/lib/constants";
1616
import { clearAllAuthCookies } from "@/utils/cookie";
1717
import type {
@@ -175,6 +175,15 @@ export class HttpClient<SecurityDataType = unknown> {
175175
private format?: ResponseType;
176176
private pendingRequests = new Map<string, Promise<any>>();
177177

178+
// 将服务端错误码/文案翻译为用户可读提示
179+
private translateErrorMessage(message?: any): string {
180+
const raw = typeof message === 'string' ? message : (message?.toString?.() || '');
181+
if (raw && /rate\s*limit|ratelimit/i.test(raw)) {
182+
return "操作过于频繁,请稍后再试";
183+
}
184+
return raw || "网络异常";
185+
}
186+
178187
constructor({
179188
securityWorker,
180189
secure,
@@ -209,13 +218,13 @@ export class HttpClient<SecurityDataType = unknown> {
209218
}
210219

211220
if (alert.error && shouldShowError) {
212-
alert.error(res.message || "网络异常");
221+
alert.error(this.translateErrorMessage(res.err));
213222
}
214223
return Promise.reject(res);
215224
}
216225

217226
if (alert.error && shouldShowError) {
218-
alert.error(response.statusText);
227+
alert.error(this.translateErrorMessage(response.statusText));
219228
}
220229
return Promise.reject(response);
221230
},
@@ -231,7 +240,7 @@ export class HttpClient<SecurityDataType = unknown> {
231240
if (typeof window !== "undefined") {
232241
console.log(
233242
"401 Unauthorized error detected, clearing auth data:",
234-
error.response,
243+
error.response.data.err
235244
);
236245

237246
// 异步清除所有认证信息,包括cookie中的auth_token
@@ -265,18 +274,18 @@ export class HttpClient<SecurityDataType = unknown> {
265274
}
266275
});
267276

268-
return Promise.reject(error.response);
277+
return Promise.reject(error.response.data.err);
269278
}
270279
}
271280

272281
// 检查请求路径,如果是 api/user 则不展示报错信息
273282
const requestUrl = error.config?.url || "";
274283
const shouldShowError = requestUrl !== "/user";
275-
276284
if (alert.error && shouldShowError) {
277-
alert.error(error.message || "网络异常");
285+
const msg = error?.response?.data?.err ?? error?.message;
286+
alert.error(this.translateErrorMessage(msg));
278287
}
279-
return Promise.reject(error.response);
288+
return Promise.reject(error.response.data.err);
280289
},
281290
);
282291
}
@@ -506,18 +515,8 @@ export class HttpClient<SecurityDataType = unknown> {
506515
}
507516
}
508517

509-
// 创建请求 Promise 并添加到待处理请求中
510-
const requestPromise = retryRequest(
511-
() => this.instance.request(requestConfig),
512-
{
513-
maxRetries: API_CONSTANTS.RETRY_ATTEMPTS,
514-
retryDelay: API_CONSTANTS.RETRY_DELAY,
515-
shouldRetry: (error) => {
516-
const status = error?.response?.status;
517-
return !status || status >= 500;
518-
},
519-
},
520-
)
518+
// 创建请求 Promise 并添加到待处理请求中(移除重试机制)
519+
const requestPromise = this.instance.request(requestConfig)
521520
.then((result) => {
522521
return result;
523522
})

ui/front/src/components/header/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ const Header = ({ brandConfig, initialForums = [] }: HeaderProps) => {
154154
onClick={handleLogoClick}
155155
/>
156156
)}
157-
{(forums?.length || 0) >= 1 && Boolean(publicAccess || user?.uid) && (
157+
{(forums?.length || 0) > 1 && Boolean(publicAccess || user?.uid) && (
158158
<ForumSelector selectedForumId={selectedForumId} forums={forums} />
159159
)}
160160
</Stack>

0 commit comments

Comments
 (0)