API契约:迁移剩余认证与公共错误

This commit is contained in:
Christ committed 2026-08-14 13:55:51 +08:00
1 parent 4e7abf61be
commit 1efe44e921
5 files changed
+89 -10

No files matched your search

+12
View File
@@ -1,9 +1,12 @@
package server
import (
"errors"
"net/http"
"github.com/go-chi/chi/v5/middleware"
"xianyu-go/internal/db"
"xianyu-go/internal/httpapi"
)
@@ -87,3 +90,12 @@ func writeErrCode(w http.ResponseWriter, status int, code, msg, requestID string
}
httpapi.WriteError(w, status, code, msg, requestID)
}
// writeCredentialVerificationError 将当前密码校验失败区分为认证失败或内部故障。
func writeCredentialVerificationError(w http.ResponseWriter, err error) {
if errors.Is(err, db.ErrPasswordMismatch) {
writeErrCode(w, http.StatusUnauthorized, "authentication_failed", "当前密码错误", "")
return
}
writeErr(w, http.StatusInternalServerError, "验证当前密码失败")
}