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
+18
View File
@@ -0,0 +1,18 @@
import type { Actor } from "@/lib/actor"
import type { ApiDecision } from "@/lib/errors"
export function allow(): ApiDecision {
return { ok: true }
}
export function deny(code: number, msg: string): ApiDecision {
return { ok: false, error: { code, msg } }
}
export function requireAuth(actor: Actor | null | undefined): ApiDecision {
if (!actor?.userId) {
return deny(401, "请先登录")
}
return allow()
}