Skip to content

优化错误响应结构,改进前端展示友好度 #144

Description

@seeker-zuo

背景

src/error.rs 已完成 orion-error 0.7 结构化错误体系重构。当前 API 错误响应格式为:

{
  "error": {
    "code": "biz.wpl_parse_error",
    "message": "WPL 解析失败\n  -> Details: 解析深度: 1\n规则 1 最深匹配字符序号 2..."
  }
}

message 字段是 display_chain() 的纯文本输出,包含 \n 换行和 -> 标记前缀,适合日志但不适合前端 UI 直接渲染。

方案

ErrorDetail 中增加 detail 字段,将诊断信息从 message 中分离:

{
  "error": {
    "code": "biz.wpl_parse_error",
    "message": "WPL 解析失败",
    "detail": "解析深度: 1\n规则 1 最深匹配字符序号 2...",
    "category": "biz"
  }
}

各字段职责:

  • code — 稳定机器可读身份码
  • message — 简短人类可读描述(AppReason 的 message 属性)
  • detail — 详细诊断信息(StructError 的 detail + source chain)
  • category — 错误分类(biz/sys,来自 identity 前缀)

前端可根据各字段独立渲染,不再需要解析纯文本标记。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions