JSON對象的_error_屬性應包含以下屬性。
### [](https://github.com/darcyliu/google-styleguide/blob/master/JSONStyleGuide.md#errorcode)error.code
~~~
屬性值類型: 整數(integer)
父節點: error
~~~
表示該錯誤的編號。這個屬性通常表示HTTP響應碼。如果存在多個錯誤,_code_應為第一個出錯的錯誤碼。
示例:
~~~
{
"error":{
"code": 404
}
}
~~~
### [](https://github.com/darcyliu/google-styleguide/blob/master/JSONStyleGuide.md#errormessage)error.message
~~~
屬性值類型: 字符串(string)
父節點: error
~~~
一個人類可讀的信息,提供有關錯誤的詳細信息。如果存在多個錯誤,_message_應為第一個錯誤的錯誤信息。
示例:
~~~
{
"error":{
"message": "File Not Found"
}
}
~~~
### [](https://github.com/darcyliu/google-styleguide/blob/master/JSONStyleGuide.md#errorerrors)error.errors
~~~
屬性值類型: 數組(array)
父節點: error
~~~
包含關于錯誤的附加信息。如果服務返回多個錯誤。_errors_數組中的每個元素表示一個不同的錯誤。
示例:
~~~
{ "error": { "errors": [] } }
~~~
### [](https://github.com/darcyliu/google-styleguide/blob/master/JSONStyleGuide.md#errorerrorsdomain)error.errors[].domain
~~~
屬性值類型: 字符串(string)
父節點: error.errors
~~~
服務拋出該錯誤的唯一識別符。它幫助區分服務的從普通協議錯誤(如,找不到文件)中區分出具體錯誤(例如,給日歷插入事件的錯誤)。
示例:
~~~
{
"error":{
"errors": [{"domain": "Calendar"}]
}
}
~~~
### [](https://github.com/darcyliu/google-styleguide/blob/master/JSONStyleGuide.md#errorerrorsreason)error.errors[].reason
~~~
屬性值類型: 字符串(string)
父節點: error.errors
~~~
該錯誤的唯一識別符。不同于_error.code_屬性,它不是HTTP響應碼。
示例:
~~~
{
"error":{
"errors": [{"reason": "ResourceNotFoundException"}]
}
}
~~~
### [](https://github.com/darcyliu/google-styleguide/blob/master/JSONStyleGuide.md#errorerrorsmessage)error.errors[].message
~~~
屬性值類型: 字符串(string)
父節點: error.errors
~~~
一個人類可讀的信息,提供有關錯誤的更多細節。如果只有一個錯誤,該字段應該與_error.message_匹配。
示例:
~~~
{
"error":{
"code": 404
"message": "File Not Found",
"errors": [{"message": "File Not Found"}]
}
}
~~~
### [](https://github.com/darcyliu/google-styleguide/blob/master/JSONStyleGuide.md#errorerrorslocation)error.errors[].location
~~~
屬性值類型: 字符串(string)
父節點: error.errors
~~~
錯誤發生的位置(根據_locationType_字段解釋該值)。
示例:
~~~
{
"error":{
"errors": [{"location": ""}]
}
}
~~~
### [](https://github.com/darcyliu/google-styleguide/blob/master/JSONStyleGuide.md#errorerrorslocationtype)error.errors[].locationType
~~~
屬性值類型: 字符串(string)
父節點: error.errors
~~~
標明如何解釋_location_屬性。
示例:
~~~
{
"error":{
"errors": [{"locationType": ""}]
}
}
~~~
### [](https://github.com/darcyliu/google-styleguide/blob/master/JSONStyleGuide.md#errorerrorsextendedhelp)error.errors[].extendedHelp
~~~
屬性值類型: 字符串(string)
父節點: error.errors
~~~
help text的URI,使錯誤更易于理解。
示例:(注:原示例這里有筆誤,中文版這里做了校正)
~~~
{
"error":{
"errors": [{"extendedHelp": "http://url.to.more.details.example.com/"}]
}
}
~~~
### [](https://github.com/darcyliu/google-styleguide/blob/master/JSONStyleGuide.md#errorerrorssendreport)error.errors[].sendReport
~~~
屬性值類型: 字符串(string)
父節點: error.errors
~~~
report form的URI,服務用它來收集錯誤狀態的數據。該URL會預先載入描述請求的參數
示例:
~~~
{
"error":{
"errors": [{"sendReport": "http://report.example.com/"}]
}
}
~~~
- Google 開源項目風格指南 (中文版)
- C++ 風格指南
- 0. 扉頁
- 1. 頭文件
- 2. 作用域
- 3. 類
- 4. 來自 Google 的奇技
- 5. 其他 C++ 特性
- 6. 命名約定
- 7. 注釋
- 8. 格式
- 9. 規則特例
- 10. 結束語
- Objective-C 風格指南
- Google Objective-C Style Guide 中文版
- 留白和格式
- 命名
- 注釋
- Cocoa 和 Objective-C 特性
- Cocoa 模式
- Python 風格指南
- Google Python 風格指南 - 中文版
- 背景
- Python語言規范
- Python風格規范
- 臨別贈言
- JSON 風格指南
- 簡介
- 定義
- 一般準則
- 屬性名準則
- 屬性值準則
- 屬性值數據類型
- JSON結構和保留屬性名
- 頂級保留屬性名稱
- data對象的保留屬性名
- 用于分頁的保留屬性名
- 用于鏈接的保留屬性名
- 錯誤對象中的保留屬性名
- 屬性順序
- 示例
- 附錄