Returning http 200 OK with error within response body

前端 未结 7 2065
遥遥无期
遥遥无期 2020-11-27 11:51

I\'m wondering if it is correct to return HTTP 200 OK when an error occurred on the server side (the error details would be contained inside the response body).

7条回答
  •  猫巷女王i
    2020-11-27 12:15

    No, this is very incorrect.

    HTTP is an application protocol. 200 implies that the response contains a payload that represents the status of the requested resource. An error message usually is not a representation of that resource.

    If something goes wrong while processing GET, the right status code is 4xx ("you messed up") or 5xx ("I messed up").

提交回复
热议问题