Questions about the Design of back-end api Interface

about back-end api interface design

Why doesn"t the backend directly use http"s status code + response body json. But to customize a format?
for example, the backend returns a 200 status code, and then uses code to represent the success or failure of the request:

{
    code:0000,
    data:{},
    msg:""
}

compared to using http status code to express: for example, throw 500402 directly, you can see the red error request directly in the browser network, what is the advantage?

Jul.14,2022
The error of

status code generally cannot enter the success callback, and the front end will not know whether there is a problem with the backend running process, or whether the backend deliberately let me know that you did not finish running, which will make the front end unable to handle it. Through the return format agreed between the front end and the front end, you can not only effectively tell the frontend what problems you encountered through code, but also give the msg message.


first of all, the two states are faced with different objects: one is the network protocol status, which is used by the browser; the other is the result returned by the request, which is used by the business object.
take Chestnut as an example, there is an insurance salesman who calls the customer. As long as the request dialed by the salesman reaches the other party's phone, the call is successful, that is, 200 is returned. But for an insurance company, it is not a success until someone answers the phone and talks for a certain period of time. Do you think you will use 200 to indicate that the insurer has completed a telemarketing or in the return structure, define a code to indicate the result of the telemarketing?

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ea3563-47a1e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ea3563-47a1e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?