在响应正文中返回http 200 OK并出错 [英] Returning http 200 OK with error within response body

查看:893
本文介绍了在响应正文中返回http 200 OK并出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道当服务器端出现错误并且响应正文内部出现错误时,返回 HTTP 200 OK 是否正确。

I'm wondering if it is correct to return HTTP 200 OK when error on server side occurred with some error inside of response body.

示例:


  1. 我们发送 http GET

  2. 服务器端出现意外情况。

  3. 服务器返回 http 200 OK 状态响应中包含错误的代码(例如 {status:发生了一些错误}

  1. We're sending http GET
  2. Something unexpected happened on the server side.
  3. Server returns http 200 OK status code with error inside a response (e.g. {"status":"some error occured"}

是否是正确的行为?我们不应该更改状态代码吗?

Is is correct behavior or not? Shouldn't we change status code?

推荐答案

不,这是非常的错误。

HTTP是一种应用程序协议.200意味着响应包含一个有效载荷,表示所请求资源的状态。错误消息通常不代表资源。

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.

如果在处理GET时出现问题,正确的状态代码是4xx(搞砸了)或5xx(我搞砸了)。

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

这篇关于在响应正文中返回http 200 OK并出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆