Repository navigation
fix: 登录不可达友好提示 + 修复 ci-backend/dependency-audit 失败 - #39
Merged
Merged
Conversation
/api 响应体为空或非 JSON(后端宕机、网关 502)时,response.json() 抛出 SyntaxError 并被直接展示给用户(Failed to execute 'json' on 'Response'...)。 改为安全解析:无法解析 JSON 时给出可读的中文提示,checkAuth 不再把后端 不可达误判为首装流程。 Co-authored-by: DSUK <2285740204@qq.com>
- TestGetSubscriptionUsage 硬编码 2026-08 周期日期,跨月后 CycleWindow 计算的当前周期不再匹配种子数据(cycle used=0)。改为运行时用与生产 代码一致的 CycleWindow 计算周期边界,断言语义不变。 - golang.org/x/crypto v0.54.0 存在 govulncheck 上报的 2 个漏洞 (ssh.Dial 可达),升级到修复版本 v0.56.0。 Co-authored-by: DSUK <2285740204@qq.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
审计主流程(登录/仪表盘/TOTP/可用性监测/设置)时发现的用户可感知问题:当后端不可达(宕机、网关 502、反向代理返回空响应体)时,登录页把
response.json()抛出的引擎级异常原文展示给用户:这是开发人员层面的原始报错,对普通用户无意义且是英文,属于主流程的高影响体验问题。
改动
1. 登录错误提示(
src/js/store.js)三个认证路径统一处理非 JSON 响应:
readJsonSafely:响应体为空或非 JSON 时返回null而非抛异常。checkAuth:Session / check-password 接口不可解析时回到登录页,不再把后端不可达误判为「首次安装 → 设置密码」流程(原先会把用户带进设置密码弹窗)。verifyPassword(密码登录):登录响应不可解析时提示「无法连接服务器,请检查网络后重试」(HTTP 异常)或「服务器响应异常,请稍后重试」(HTTP 200 但响应异常);catch 分支同样把Failed to fetch/Unexpected end of JSON input类错误映射为友好文案。正常错误路径不受影响:后端返回的 JSON 错误(如「密码错误,还剩 N 次尝试机会」)仍原样展示,成功登录、2FA、429 限流等既有分支不变。
2. ci-backend 失败:测试跨月失效(
backend-go/internal/subscription/service_test.go)TestGetSubscriptionUsage硬编码2026-08-01→2026-09-01作为「当前周期」种子数据,而生产代码用CycleWindow(now, …)按当前日期计算周期窗口——9 月 1 日之后种子行不再落在「当前周期」,cycleUsedBytes恒为 0 导致断言失败(与产品代码正确性无关)。修复为运行时用与生产代码一致的CycleWindow计算周期边界,断言语义不变。3. dependency-audit 失败:Go 漏洞升级(
backend-go/go.mod/go.sum)golang.org/x/crypto@v0.54.0存在 govulncheck 上报的 2 个漏洞(ssh.Dial可达,修复版本 v0.56.0),升级到 v0.56.0 并go mod tidy。验证
npm run lint通过;npm run test(vitest 42 文件 / 401 用例)通过;npm run governance:check通过;npm run ui:governance通过。go test ./...(backend-go 全部包)通过;go build ./cmd/api-monitor通过。npm audit --audit-level=high0 漏洞;针对./internal/serveragent等包运行 govulncheck 无漏洞(完整./...扫描在本沙箱受内存上限限制被终止,CI 环境不受此限)。修复前(后端不可达)
修复后(后端不可达)
注:截图为非视觉证据(DOM 文本快照对应文字:「登录失败 Failed to execute 'json'…」→「登录失败 无法连接服务器,请检查网络后重试」),像素级观感未单独验证。