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

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

主站蜘蛛池模板: 甘泉县| 友谊县| 武威市| 太保市| 开远市| 桃江县| 新巴尔虎右旗| 牙克石市| 东乡族自治县| 合山市| 惠安县| 万宁市| 交城县| 大关县| 广汉市| 车致| 鄱阳县| 万荣县| 如东县| 芒康县| 五常市| 沂南县| 都江堰市| 德惠市| 思南县| 潼关县| 海口市| 滕州市| 昌乐县| 隆德县| 西安市| 龙里县| 安乡县| 莱西市| 商丘市| 绥中县| 富川| 河西区| 兴安县| 金乡县| 舒城县|