注册期间现有电子邮件的422或409状态代码 [英] 422 or 409 status code for existing email during signup

查看:195
本文介绍了注册期间现有电子邮件的422或409状态代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建RESTful API,遇到了一种情况.在用户注册期间,如果电子邮件已经存在,则在422409之间,哪个HTTP响应代码有意义?

我浏览了类似的 one 和接受的答案是从2012年开始的.答案仍然有效吗?例子会很有帮助.

I am building RESTful API and I have come across a situation. During user sign up, if the email already exists then between 422 and 409 which http response code makes sense?

I have browsed through similar one and the accepted answer is from the year 2012. Does the answer still hold good? Examples would be of great help.

推荐答案

一旦这两个问题都 422 适用于这种情况(我会选择 409 ).

You may not find a very definitive answer to this question, once both 409 and 422 would be suitable for this situation (I would go for 409 though).

对于其中任何一个,您必须确保将描述问题的有效负载发送回客户端.

For any of them, you must ensure that a payload describing the problem is sent back to the client.

6.5.8. 409冲突

409(冲突)状态代码表示请求无法 由于与目标的当前状态冲突而完成 资源.该代码用于用户可能会 能够解决冲突并重新提交请求.服务器 应该生成一个有效载荷,该有效载荷应为用户提供足够的信息 识别冲突的根源. [...]

The 409 (Conflict) status code indicates that the request could not be completed due to a conflict with the current state of the target resource. This code is used in situations where the user might be able to resolve the conflict and resubmit the request. The server SHOULD generate a payload that includes enough information for a user to recognize the source of the conflict. [...]

11.2. 422无法处理的实体

422(不可处理实体)状态代码表示服务器 了解请求实体的内容类型(因此 415(不受支持的媒体类型)状态代码不合适),并且 请求实体的语法正确(因此400(错误请求) 状态代码不正确),但无法处理其中包含的内容 指示.例如对于如果XML可能会出现此错误情况 请求正文包含格式正确(即语法正确)的内容,但 语义错误的XML指令.

The 422 (Unprocessable Entity) status code means the server understands the content type of the request entity (hence a 415 (Unsupported Media Type) status code is inappropriate), and the syntax of the request entity is correct (thus a 400 (Bad Request) status code is inappropriate) but was unable to process the contained instructions. For example, this error condition may occur if an XML request body contains well-formed (i.e., syntactically correct), but semantically erroneous, XML instructions.

这篇关于注册期间现有电子邮件的422或409状态代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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