This is the return code of the WeChat public platform interface. When working on a project, you need the API interface return code. I want to know how to design the API interface return code?
What I mean is how to design different return codes to represent different meanings. For example, 40001 means XXX means, 40002 means XXX means. Should these be designed like this? Thank you everyone
黄舟2017-06-12 09:21:41
In application development, it is better to use error names than error codes, and the code is more readable.
Imagine your client code:
if (error === 'ERROR_INVALID_ACCESS_TOKEN') { ... }
vs
if (error === 40010) { ... }
Domestic API providers sometimes use numeric error codes to take care that domestic developers are not familiar with English (or the API developers themselves do not remember English names).
Digital codes are of greater significance at the system level because of high transmission efficiency (such as binary protocols). For a large number of JSON format string transmission protocols, this efficiency is not important.
Readability is much more important, and error names have the advantage of being unstructured and scalable compared to error codes.
迷茫2017-06-12 09:21:41
Give you my thoughts,
Special return code: (common to all interfaces)
0, represents success
-1, represents internal server error
Common error return code:
The first number represents return to different interfaces,
The rest are error types, ordered in descending order of importance.
In fact, there is no need to study it in such depth. I think this is enough.
It’s similar to WeChat.
The important thing is to keep it simple.
高洛峰2017-06-12 09:21:41
You can learn from Microsoft, for example, ERROR_SUCCESS is 0, which means success. Error codes are defined starting at 1 and going up to over 10,000. Then you can divide the error codes into some intervals, such as 1~1000, 1001~2000, 2001~3000, etc., to determine what type of meaning they represent respectively. Then each interval can be defined starting from the basic error codes that can be thought of, and then It can also be amplified in small amounts.