知识卡片
错误结果必须进入契约
接口不能只规定成功路径;未找到、无效请求、部分失败与内部故障须有可区分的结果语义。可用协议状态码或明确错误对象,但应文档化并在契约测试中验证。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
原书出处
参考来源
- 位置:《Principles of Software Architecture Modernization》第6章《Principles of Proper Services》(源文件:`_epub-src/OPS/ch06.xhtml`,归一化正文 [75922:80097))
- 结论依据:原文强调错误处理是契约的重要部分,列出 null、异常映射、协议状态码、空对象与自定义错误对象等选择。
- 原始内容:Handling errors in contracts Error handling is a critical element of your contract. Code 6.1 and 6.2 in effect only cover the happy path; there is no description of what errors are returned or what useful information could be conveyed. Every language and API protocol has its own convention and ways of handling this concern.