官术网_书友最值得收藏!

Returning errors

In the instance of failure, users of your API should be able to write one piece of code that handles errors across different endpoints. A standard error entity will help your consumers by enabling them to write DRY code whenever an error caused by client or server occurs.

The Microsoft API guidelines recommend the following format for these entities:

{ 
"error": {
"code": "BadArgument",
"message": "Previous passwords may not be reused",
"target": "password",
"innererror": a {
"code": "PasswordError",
"innererror": {
"code": "PasswordDoesNotMeetPolicy",
"minLength": "6",
"maxLength": "64",
"characterTypes": ["lowerCase","upperCase","number","symbol"],
"minDistinctCharacterTypes": "2",
"innererror": {
"code": "PasswordReuseNotAllowed"
}
}
}
}
}

ErrorResponse: Object

The ErrorResponse is the top level object which will be returned by our response and contains the following fields:

 

Error: Object

The Error object is the detail for our error response; it provides full detail for the reason that the error occurred:

InnerError: Object

 

Microsoft has provided an excellent API guidelines resource, you can read more about returning errors by looking at the following link:

https://github.com/Microsoft/api-guidelines/blob/master/Guidelines.md#51-errors

主站蜘蛛池模板: 凉城县| 应城市| 齐河县| 乐清市| 玉龙| 大冶市| 腾冲县| 靖远县| 莫力| 东方市| 墨脱县| 罗源县| 正蓝旗| 大安市| 万安县| 右玉县| 连云港市| 灯塔市| 南通市| 固阳县| 墨玉县| 广河县| 兴化市| 平定县| 昭觉县| 岳池县| 平邑县| 新乐市| 喀喇| 乳山市| 旬邑县| 永泰县| 华坪县| 新兴县| 安图县| 扬州市| 泸溪县| 双柏县| 太谷县| 建阳市| 凤城市|