- Building Microservices with Go
- Nic Jackson
- 171字
- 2021-07-15 17:28:13
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
- Learning LibGDX Game Development(Second Edition)
- 大話PLC(輕松動(dòng)漫版)
- Python數(shù)據(jù)分析入門與實(shí)戰(zhàn)
- MySQL數(shù)據(jù)庫應(yīng)用與管理 第2版
- 樂學(xué)Web編程:網(wǎng)站制作不神秘
- Practical Data Science Cookbook(Second Edition)
- Android 9 Development Cookbook(Third Edition)
- 編程珠璣(續(xù))
- Learning AWS Lumberyard Game Development
- Mastering Scientific Computing with R
- Building Minecraft Server Modifications
- Clojure Reactive Programming
- C++新經(jīng)典
- Working with Odoo
- Creating Stunning Dashboards with QlikView