Page:
T-232
Pages
00-ai-start-here
01-vision
02-requirements
03-tech-stack
04-architecture
05-coding-rules
06-tasks
07-user-stories
08-interaction-checklist
Design
Home
Integrations-shunyunbao-contract
PPT
T-001
T-002
T-003
T-004
T-101
T-102
T-103
T-104
T-201
T-202
T-203
T-204
T-205
T-206
T-207
T-208
T-209
T-210
T-211
T-212
T-213
T-214
T-215
T-216
T-217
T-218
T-219
T-220
T-221
T-222
T-223
T-224
T-225
T-226
T-227
T-228
T-229
T-230
T-231
T-232
T-233
T-234
T-235
T-236
T-237
T-238
T-239
T-240
T-241
T-242
T-243
T-244
T-245
T-246
T-247
T-248
T-249
T-250
T-251
T-252
T-253
T-254
T-255
T-256
T-257
T-258
T-259
T-260
T-261
T-262
T-263
T-264
T-265
T-266
T-267
T-268
T-269
T-270
T-271
T-272
T-273
T-274
T-275
T-276
T-277
T-278
T-279
T-280
T-281
Task-Template
Tasks
agent-context
api
clean-state-checklist
current-state
routes
Clone
This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
同步来源:
docs/tasks/T-232.md· commitafc651f75a3a
id: T-232 title: 记录 ERP 货运导入预检的安全诊断日志 phase: 2 deps:
- T-231
status: DONE
created: 2026-07-29
context_ref:
5ed27afwork_branch: null write_paths: - docs/tasks/T-232.md
- docs/current-state.md
- backend-api/cmd/api/**
- backend-api/internal/transport/webui/**
问题 / 背景
T-231 已将 ERP/OCR 导入预检失败映射成 Admin 页面和 JSON API 的稳定错误码,但 SSR
handler 未把该错误码写入 API 进程日志。现场遇到 503 时,部署者无法从启动终端确认是
OCR 服务、ERP 连通性还是协议错误;直接记录底层 error 又可能泄露 ERP 响应、Cookie、
账号、密码或验证码。
方案
- 为 Admin Web handler 注入可选事件记录器;API 入口把它连接到标准日志。
- 仅在
/freight/import的稳定预检失败分支记录固定事件名、稳定错误码和最终 HTTP 状态,例如freight_import_preflight_failed code=ERP_UNAVAILABLE status=503。 - 未归类的创建失败只记录固定事件名和状态,不拼接原始 error、单号、幂等键、请求头、 OCR 文本或 ERP 响应。
- 以 handler 测试固定日志内容,验证可定位稳定失败类别且不包含伪造的敏感上游文字。
验收要点
/freight/import的五类稳定预检错误在 API 终端均有可搜索的 code 和 HTTP 状态。- 页面和 JSON 响应继续只返回匿名公开提示,日志不包含单号、凭证、Cookie、验证码、 OCR 文本或 ERP 原始正文。
- 历史
NewHandler调用保持兼容;日志记录器缺省为安全 no-op。 go test ./...、go test -race ./...、go vet ./...和三个 Go 入口构建通过。
边界
- 不修改 ERP/OCR 请求、重试、错误映射、数据库 schema 或采购任务流程。
- 不执行真实 ERP/OCR 请求;运行时日志由部署者在重启后的受控单号导入中观察。
执行记录
- 2026-07-29:创建任务。现场检查时本机
8080无监听进程,无法回放先前503;确认 T-231 的 SSR 分支会渲染稳定 code,但未向 API 终端写入任何诊断事件。 - 2026-07-29:API 入口向 Web handler 注入标准日志;五类稳定预检错误记录固定事件、code
和 status,未知失败也只记录固定事件/status。
go test ./...、go test -race ./...、go vet ./...及 api/migrate/authctl 构建均通过。