fix(admin): show login API error toast on 401

Anonymous auth 401s skip the global message handler, so wrong
credentials left the login form silent; surface the server detail.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
wuzilongandCursor committed 2026-11-10 16:09:48 +08:00
1 parent 24b51070e0
commit 15bc1f10fa
1 file changed
+6 -2
+6 -2
View File
@@ -161,7 +161,7 @@
})
if (!result?.token) {
throw new Error('Login failed - no token received')
throw new Error('登录失败,未返回令牌')
}
const permissions = result.permissions || []
@@ -181,8 +181,12 @@
const redirect = route.query.redirect as string
router.push(redirect || '/')
} catch (error) {
if (!(error instanceof HttpError)) {
// 匿名登录接口的 401 不会走全局 showError,需在此提示服务端 detail。
if (error instanceof HttpError) {
ElMessage.error(error.message)
} else {
console.error('[Login] Unexpected error:', error)
ElMessage.error(error instanceof Error ? error.message : '登录失败,请稍后重试')
}
await loadCaptcha()
} finally {