Returning http 200 OK with error within response body

前端 未结 7 1984
遥遥无期
遥遥无期 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条回答
  • 2020-11-27 12:17

    To clarify, you should use HTTP error codes where they fit with the protocol, and not use HTTP status codes to send business logic errors.

    Errors like insufficient balance, no cabs available, bad user/password qualify for HTTP status 200 with application specific error handling in the response body.

    See this software engineering answer:

    I would say it is better to be explicit about the separation of protocols. Let the HTTP server and the web browser do their own thing, and let the app do its own thing. The app needs to be able to make requests, and it needs the responses--and its logic as to how to request, how to interpret the responses, can be more (or less) complex than the HTTP perspective.

    0 讨论(0)
提交回复
热议问题