当前位置:网站首页>Response result definition specific error code
Response result definition specific error code
2022-04-22 00:32:00 【Gentleman jiejie】
Generally speaking , We define a uniform return result set object , Most will be defined as follows :

At least many of my previous projects only defined the above attributes , It seems to be enough .
If the above code The return value of the status code defines the sum http There's no difference in response codes , So to be honest , It's hard to tell what's wrong , For example, a very rough handle code The status code is defined as 200 and 500, Success is 200, The error is 500, It may be OK to use it in the short term , The front end can also judge according to these two status codes , However, if it is necessary to provide open interfaces for other projects in the later stage , This definition is not accurate , Too broad a status code , It will make it difficult for users to handle our open interface in line with their own business . After all, errors return 500, If you want the prompt to be accurate , The user can directly throw out the error and exception information of the remote calling interface , But this is tantamount to giving the user experience to the perfection of the third-party interface , Normally , We should allow users to distinguish different exceptions through status codes , The status code corresponding to each case should be different , We should also maintain the corresponding information document of the status code , In this way, users can connect according to their own business conditions , Judge what is wrong according to the status code , Then further encapsulate the error or throw it directly .
In fact, the above code Attribute can be used as specific status code and corresponding to exception information , It just depends on whether we use it well , Whether the status code is defined in detail .
PS: This time just share and record your thoughts , At the same time, it is suggested to define the status code completely at the beginning of the project , Don't throw everything away 500, The finer the definition , In fact, the lower the coupling , Users are also more assured when docking .
版权声明
本文为[Gentleman jiejie]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220024213779.html
边栏推荐
- L1-020 帅到没朋友
- How did I get a monthly salary of 20K when I changed from zero basis to network worker? Share the learning route of network worker system
- How to choose the current limiting resistor of Zener diode
- go操作mysql
- 架构实战营-模块三-作业
- Application and analysis of TVS Diode
- Share the 28 we media tools I often use and collect them quickly. If 20000 videos are played, there will be 264 benefits
- 等待wait(),wait(long),wait(long,int)/通知机制notify(),notifyAll()
- OJ daily practice - factorial sequence and
- Knock stupid l1-059
猜你喜欢
随机推荐
L1-043 阅览室
物联网专业未来没有前途了吗?
L1-025 positive integer a + B
面试题8——捕获的雨水
Blender MMD export FBX models and bake animations
Main parameters and structure of LED
On the happiness of fishing -- April 20
Simple use of OpenSSL
Basic knowledge of diode
容器雲系列之容器技術相關概念介紹
uniapp+php开发的影票返利系统,可完美运营
GDB debug application record
OJ daily practice - number of daffodils
笔记本拓展外接显示器时 鼠标移动不到主显示器外的另一块屏上
L1-020 帅到没朋友
活动预告 | 4月23日,多场OpenMLDB精彩分享来袭,不负周末好时光!
Unity determines whether the file (under the local absolute directory) exists
SqlServer——正则表达式
What has changed since Huawei Routing & Switching switched to datacom
HDU - 1561 the more, the better








![[sctf2019] flag shop Erb template injection](/img/d7/ff19478a39bd2d189cfc4c8fe8763f.png)
