博客评论限流5/min,添加前端错误处理

This commit is contained in:
2025-06-19 15:42:38 +08:00
parent 91a60e8cf5
commit 1f1950551e
2 changed files with 23 additions and 16 deletions

View File

@@ -32,12 +32,20 @@ export function BlogCommentTool({ blogId, onInsertComment, replayTarget, handleC
const submit = async () => {
if (comment.trim().length === 0) return;
const res = await BlogApi.createComment(blogId, comment, replayTarget ? replayTarget.id : undefined);
if (res) {
toast.success('发布成功');
setComment('');
onInsertComment(res);
handleClearReplayTarget();
try {
const res = await BlogApi.createComment(blogId, comment, replayTarget ? replayTarget.id : undefined);
if (res) {
toast.success('发布成功');
setComment('');
onInsertComment(res);
handleClearReplayTarget();
}
} catch (error: any) {
if (error.statusCode === 429) {
return toast.error('操作太频繁了,稍后再试吧')
}
toast.error('发布失败')
}
}