知识卡片
错误响应需要可读原因
错误状态码说明失败类别,响应载荷还应给出可读原因,帮助客户端定位具体问题。书中示例可以用 error、detail 或 message 字段;字段名应在接口契约中统一,避免不同端点让调用方反复猜测。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
原书出处
参考来源
- 位置:《Microservice APIs》第 4 章《Principles of REST API design》(源文件:_epub-src/OEBPS/Text/04.htm)
- 结论依据:原文要求错误响应体解释为什么报错,并列出 error、detail、message 等常见字段名。
- 原始内容:Error responses’ payloads should include an "error" keyword detailing why the client is getting an error. ... "error" is a commonly used keyword for error messages, but you can also use other keywords such as "detail" and "message" .