Update notify.ts
This commit is contained in:
1 parent
05b22247e0
commit
34815476f2
1 file changed
+8
-1
@@ -86,6 +86,7 @@ async function fetchLatestComments(): Promise<ArtalkComment[]> {
|
||||
// 使用管理员 API 获取所有评论
|
||||
const url = `${ARTALK_SERVER}/api/v2/admin/comments?site_name=${encodeURIComponent(ARTALK_SITE)}&limit=5&sort_by=date&sort_order=desc`;
|
||||
console.log("[comment-notify] fetching comments with admin API...");
|
||||
console.log("[comment-notify] URL:", url);
|
||||
|
||||
const res = await fetch(url, {
|
||||
headers: {
|
||||
@@ -94,13 +95,16 @@ async function fetchLatestComments(): Promise<ArtalkComment[]> {
|
||||
},
|
||||
});
|
||||
|
||||
console.log("[comment-notify] response status:", res.status, res.statusText);
|
||||
|
||||
if (!res.ok) {
|
||||
const errorText = await res.text().catch(() => "Unable to read response");
|
||||
console.error("[comment-notify] fetch failed:", res.status, res.statusText);
|
||||
console.error("[comment-notify] response:", errorText);
|
||||
console.error("[comment-notify] response body:", errorText);
|
||||
|
||||
// 如果是认证失败,清除 token 以便下次重试
|
||||
if (res.status === 401 || res.status === 403) {
|
||||
console.error("[comment-notify] authentication failed, clearing token");
|
||||
authToken = null;
|
||||
tokenExpiry = 0;
|
||||
}
|
||||
@@ -113,6 +117,9 @@ async function fetchLatestComments(): Promise<ArtalkComment[]> {
|
||||
return data.comments || [];
|
||||
} catch (e) {
|
||||
console.error("[comment-notify] fetch error:", e instanceof Error ? e.message : String(e));
|
||||
if (e instanceof Error && e.stack) {
|
||||
console.error("[comment-notify] error stack:", e.stack.split('\n').slice(0, 5).join('\n'));
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user