知识卡片
语法错误与语义错误分辨
请求载荷解析失败与解析成功但不满足业务结构是两类问题:畸形 JSON 属于语法错误,书中示例返回 400;缺少订单必填字段等是可解析但无法处理的内容,示例文字使用 422。分开识别能让客户端知道该修格式还是修字段。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
原书出处
参考来源
- 位置:《Microservice APIs》第 4 章《Principles of REST API design》(源文件:_epub-src/OEBPS/Text/04.htm)
- 结论依据:原文区分 invalid syntax 与 unprocessable entities,并分别以畸形 JSON、缺必填字段说明 400 与 422 的用途;图注另有不一致,待审查复核。
- 原始内容:Payloads with invalid syntax are payloads that the server can neither parse nor understand. A typical example of a payload with invalid syntax is malformed JSON. ... Unprocessable entities are syntactically valid payloads that miss a required parameter, contain invalid parameters, or assign the wrong value or type to a parameter. ... We address this type of error with the 422 (Unprocessable Entity) status code