refactor(errors): migrate decisions to {code,msg}

This commit is contained in:
zetaloop
2026-02-28 07:21:51 +08:00
parent 4e2ee5be54
commit cc24a0cbc3
23 changed files with 157 additions and 165 deletions
+3 -3
View File
@@ -1,5 +1,5 @@
import { addNotification } from "@/lib/api/notifications"
import { allow, deny } from "@/lib/policy/assert"
import { allow, deny } from "@/lib/decision"
import { useAuthStore } from "@/store/auth"
import { usePostStore } from "@/store/posts"
@@ -18,12 +18,12 @@ export function listPostsByAuthor(userId: string) {
export function togglePostLike(postId: string) {
const user = useAuthStore.getState().user
if (!user) {
return deny("AUTH_REQUIRED", "请先登录")
return deny(401, "请先登录")
}
const post = usePostStore.getState().posts.find((item) => item.id === postId)
if (!post) {
return deny("NOT_FOUND", "帖子不存在")
return deny(404, "帖子不存在")
}
const shouldNotify = !post.liked