Skip to content

Let's use AI to Earn!

jingmochuli

bulaienaofutuojiesenzhangc89dd6d24c30
diff --git a/src/api/notification.ts b/src/api/notification.ts
index 8ae53993..f19f44de 100644
--- a/src/api/notification.ts
+++ b/src/api/notification.ts
@@ -54,7 +54,7 @@ export const markAllNotificationsAsRead = () => {
// 获取未读数量
export const getUnreadCount = () => {
- return http.get<UnreadCountResponse>("notification/unread-count");
+ return http.get<UnreadCountResponse>("notification/unread-count", undefined, true);
};
// 删除通知
diff --git a/src/utils/request.ts b/src/utils/request.ts
index 52eabe23..9474e599 100644
--- a/src/utils/request.ts
+++ b/src/utils/request.ts
@@ -10,6 +10,10 @@ type ResponseType<T> = {
url: string;
};
+type RequestParamsWithSilent = RequestParams & {
+ silent?: boolean; // 是否静默处理错误,不显示提示
+};
+
const fetchService = new FetchService({
baseURL: `${process.env.NEXT_PUBLIC_API_URL}/`,
requestInterceptor(requestParams) {
@@ -36,7 +40,7 @@ const fetchService = new FetchService({
},
});
-export async function request<T>(params: RequestParams) {
+export async function request<T>(params: RequestParamsWithSilent) {
try {
const res = await fetchService.request(params);
const data: ResponseType<T> = await res.json();
@@ -63,19 +67,20 @@ export async function request<T>(params: RequestParams) {
}
if (data.code !== 0) {
- if (typeof window !== "undefined")
+ if (!params.silent && typeof window !== "undefined") {
message.warning({
content: `${data.message || i18nText.networkBusy} ${i18nText.contact} https://t.me/harryyyy2025`,
key: "apiErrorMessage",
duration: 6,
});
+ }
return null;
}
return data;
} catch (e) {
console.warn(e);
- if (typeof window !== "undefined") {
+ if (!params.silent && typeof window !== "undefined") {
message.error({
content: `${(useUserStore.getState().lang || "zh-CN").toLowerCase().startsWith("zh") ? "网络异常,请稍后重试!" : "Network error, please try again later!"} ${(useUserStore.getState().lang || "zh-CN").toLowerCase().startsWith("zh") ? "如需帮助请联系客服:" : "Need help? Contact support:"} https://t.me/harryyyy2025`,
key: "apiErrorMessage",
@@ -87,32 +92,36 @@ export async function request<T>(params: RequestParams) {
}
export default {
- get<T>(url: string, data?: any) {
+ get<T>(url: string, data?: any, silent?: boolean) {
return request<T>({
url,
params: data,
method: "GET",
+ silent,
});
},
- post<T>(url: string, data?: any) {
+ post<T>(url: string, data?: any, silent?: boolean) {
return request<T>({
url,
data: data,
method: "POST",
+ silent,
});
},
- put<T>(url: string, data?: any) {
+ put<T>(url: string, data?: any, silent?: boolean) {
return request<T>({
url,
data: data,
method: "PUT",
+ silent,
});
},
- delete<T>(url: string, data?: any) {
+ delete<T>(url: string, data?: any, silent?: boolean) {
return request<T>({
url,
data: data,
method: "DELETE",
+ silent,
});
},
};