- 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
- ASP.NET Core:Cloud-ready,Enterprise Web Application Development
- iOS Game Programming Cookbook
- Kibana Essentials
- CockroachDB權威指南
- Microsoft Dynamics 365 Extensions Cookbook
- PHP+MySQL網站開發技術項目式教程(第2版)
- 羅克韋爾ControlLogix系統應用技術
- Java游戲服務器架構實戰
- 差分進化算法及其高維多目標優化應用
- SSM輕量級框架應用實戰
- 深入RabbitMQ
- C和C++游戲趣味編程
- Python Deep Learning
- Appcelerator Titanium:Patterns and Best Practices
- Python一行流:像專家一樣寫代碼