[1] 422
(Unprocessable Entity)
は、要求の payload body に含まれているデータが構文的には正しいものの、
内容が仕様的に正しくなく処理できないことを表す状態符号です。
[4] 422
は、鯖が要求の payload body の
MIME型は理解でき、構文的には正しかったものの、
記述されている指示に従って処理することはできなかったことを表す状態符号です >>3。
[23]
このように 4xx
エラーの意味はかなり細分されていて、
一見便利そうですが、
実応用に当てはめて考えてみるとその使い分けは必ずしも明確とはいえません。
一方で、
エラーの細分化は要求の送信者に十分な情報を与えることが主たる目的ですが
(他にはサーバーのアクセスログからエラーの分析を行うための便宜というのもあるでしょう)、
そのために十分なほどに細分化されているとはいえません。
つまり帯に短し𧜎に長しというべき状況なのであります。
[24]
応用は、
状態符号の選択に迷うのであれば、
400
を使えばよろしいでしょう。
適用可能性に自信がないところで敢えて 422
を使う必要性はありません。
エラーの詳細は、
応答に
JSON
形式で含めるなり、
HTTPヘッダーに適宜記述するなり、
クライアントが扱いやすい方法を採ればよい。
[13] PATCH
要求の payload body を理解できるものの、
処理はできない場合には、 422
応答を返すべきです >>12。
[9] 要求で JSON を求める Web API で、入力が期待される構造でなかった時に
422
応答が返されることがよくあります。
[15] Linked Data Patch Format ( 版) https://dvcs.w3.org/hg/ldpwg/raw-file/ldpatch/ldpatch.html#h-error-handling
If a server receives a search request but cannot process the request
because it does not support a particular style of partial match
searching, it SHOULD return an HTTP 422 (Unprocessable Entity)
[RFC4918] response. When returning a 422 error, the server MAY also
return an error response body as specified in Section 6 of [RFC7483]
if the requested media type is one that is specified in [RFC7480].
422 Invalid request. The request body is parse-able however with invalid content or there are issues with a rider's user account.
422 - Event source does not exist.
422 - Channel not in Stasis application
422 — Unprocessable Entity
Something with the message isn’t quite right, this could be malformed JSON or incorrect fields. In this case, the response body contains JSON {ErrorCode: 405, Message: "details"} with an API error code and message containing details on what went wrong.
InvalidInput 422 The given request was not valid. The message key of the response will hold an explanation of the invalid input.
[21] RFC 5323 - Web Distributed Authoring and Versioning (WebDAV) SEARCH () https://tools.ietf.org/html/rfc5323#section-5.11
[22]
GitHub
の
API
は要求に含まれる公開鍵が未対応の形式 (秘密鍵形式の場合を含みます。)
のとき、
422
を返すようです。
422
Validation failed
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
(処理不能実体) 状態符号は、
サーバーが要求実体の内容型は理解した
(従って 415
(未対応の媒体型) 状態符号は不適切である)
し、要求実体は正しい (従って 400
(悪い要求)
状態符号は不適切である) ものの含まれている指示を処理することができなかったことを意味します。
例えば、 XML 要求本体が整形式である (つまり構文的には正しい)
が意味的に誤っている XML 指示のときにこの誤り状況が発生するかもしれません。
[8] S-HTTP は別の意味 (SHTTP Proxy Authentication Required) で使っていました >>423。
415
がより適当です >>3。