Repository navigation
Conversation
后端(issue #222): - response 包唯一错误出口生成 error_id = DI-<业务码>-<8位大写hex>, 存 gin 上下文(供 R-96 access 日志 / R-98 Sentry tag 同源取用), 并打一行含同编号的 ERROR 日志;成功信封 omitempty 不携带 - 契约三处同步:api/openapi.yaml Envelope.error_id + 双端生成物 前端: - resolveErrorKind 纯函数六档分型(canceled/offline/timeout/network/server/business), 断网优先于超时,避免给「可重试」假线索;ApiClientError 透传信封 error_id - lib/describeApiError:buildReportText(编号/请求 id/业务码/路由/版本/时间, componentStack 截断)+ describeApiError 唯一文案出口 + notifyApiError (canceled 静默、offline 无编号;messageApi 注入 App.useApp 实例) - ErrorBoundary:显示编号(若有)+ 复制报障信息按钮 - 高频入口(列表页/取数失败/保存失败)29 处替换 message.error(error.message) - business 档优先后端 msg 原样展示(该文案本就面向用户,Dashboards 测试钉死); server 档刻意不用原文(dial tcp 内部细节只给编号) 测试:response 包信封/日志同源用例;assertBody 把随机 error_id 剥出单独校验 (错误信封必须带合法编号);前端六档表驱动 + 断网无编号 + 渲染探针; 真实浏览器 E2E:死端口连库 toast 带编号、点击复制成功反馈、 离线 + 后端停机场景文案无编号
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.
做了什么
对应 issue #222(R-97),依赖的 R-96/#241、R-99/#224、R-100/#242 尚未合入,相关集成点按下表降级处理(均有注释锚点)。
后端
internal/response:writeError唯一出口生成error_id = DI-<业务码>-<8位大写hex>(如DI-50000-3F7A2C9B),写入信封新字段error_id(成功信封 omitempty)、存c.Set("error_id")(供 R-96 access 日志 / R-98 Sentry tag 同源取用,两 PR 合入时改为读这里)、打一行ERROR request failedslog(含同编号)。api/openapi.yamlEnvelope.error_id +gen_types.go+gen_types.ts(api-gen 前端半步仍坏,手工同步)。前端
resolveErrorKind纯函数六档:canceled → offline(断网优先于超时,不给假线索)→ timeout → network → business → server,兜底 network。ApiClientError透传信封error_id与原始 axios code,构造时算出kind。lib/describeApiError.ts:buildReportText(Error ID / Request ID / Biz code / HTTP status / Route / Version / Time,componentStack 截 800 字符)、describeApiError唯一文案出口、notifyApiError(canceled 静默;offline 无编号;messageApi 第三参注入App.useApp()实例——antd 静态 message 在 App 上下文外渲染不可靠)。ErrorBoundary:显示编号(若有)+「复制报障信息」按钮(antd copyable)。message.error(error.message):Dataset(8)/Dashboards(9)/DatasetDetail(7)/Datasource(3)/DashboardEditor(2)/ChartBuilder(1),共 30 处。dial tcp内部细节只给编号。测试证据
go test -race ./...27 包全绿。response 包新增信封格式/编号唯一/context 同源/ERROR 日志同源/成功信封不带编号用例;assertBody把随机 error_id 从逐字节比对中剥出单独校验(错误信封必须带合法编号,比原契约更严)。pnpm build:check全绿(biome + tsc + vitest 975 用例)。新增六档表驱动、断网无编号、notifyApiError 静默/带编号、渲染探针(App.useApp 实例真渲染进 DOM)等 26 个用例。(Error ID: DI-20100-C00AB942, click to copy diagnostic info),两次触发编号不同;navigator.onLine=false+ 停掉后端 → 触发请求 → toast「You are offline. Check your connection and try again.」无任何编号(截图见 CI 或可复跑:仓库根.env起服务即可复现)。评审需留意
c.Get("error_id")取编号(response 包已留注释锚点);R-99/[P1] R-99 稳定错误码与文案分离:error.code/hint_key + 越权码 + 三方一致性测试 #224 合入后 business 档可接 hint_key 文案表;复制文本的Version: dev占位待 R-100/225: R-100 版本与运行状态可见(ldflags / -version / /version / /health 三级) #242 提供运行时版本。App.useApp()的 message 实例;未传时回退 antd 静态 message(lib 单测走该路径)。本次替换的 30 处所在页面均已持有实例。IntlProvider(ChartBuilder 组件现在消费 useIntl);Dashboards 一个用例的 mock 从裸Error改为ApiClientError(与拦截器生产形态一致,断言原文未变)。