Browse Source

Return 422 instead of 400 when AcceptResource returns false

422 is undefined for HTTP and interpreted as 400.
Loïc Hoguin 11 years ago
parent
commit
4eee573700
4 changed files with 7 additions and 7 deletions
  1. BIN
      guide/rest_put_post_patch.png
  2. 5 5
      guide/rest_put_post_patch.svg
  3. 1 1
      src/cowboy_rest.erl
  4. 1 1
      test/http_SUITE.erl

BIN
guide/rest_put_post_patch.png


+ 5 - 5
guide/rest_put_post_patch.svg

@@ -65,8 +65,8 @@
      inkscape:pageopacity="1"
      inkscape:pageopacity="1"
      inkscape:pageshadow="2"
      inkscape:pageshadow="2"
      inkscape:zoom="2"
      inkscape:zoom="2"
-     inkscape:cx="-3.9389218"
-     inkscape:cy="344.00863"
+     inkscape:cx="299.56028"
+     inkscape:cy="-395.99137"
      inkscape:document-units="px"
      inkscape:document-units="px"
      inkscape:current-layer="layer1"
      inkscape:current-layer="layer1"
      showgrid="false"
      showgrid="false"
@@ -1329,7 +1329,7 @@
     <text
     <text
        xml:space="preserve"
        xml:space="preserve"
        style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#77823c;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
        style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#77823c;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
-       x="604.3656"
+       x="604.32263"
        y="1242.303"
        y="1242.303"
        id="text5371-43-2-9-7-3-8"
        id="text5371-43-2-9-7-3-8"
        sodipodi:linespacing="125%"
        sodipodi:linespacing="125%"
@@ -1338,8 +1338,8 @@
        inkscape:export-ydpi="89.926643"><tspan
        inkscape:export-ydpi="89.926643"><tspan
          sodipodi:role="line"
          sodipodi:role="line"
          id="tspan5373-3-9-7-8-7-5"
          id="tspan5373-3-9-7-8-7-5"
-         x="604.3656"
-         y="1242.303">422 unprocessable entity</tspan></text>
+         x="604.32263"
+         y="1242.303">400 bad request</tspan></text>
     <g
     <g
        transform="matrix(-0.34202014,-0.93969262,0.93969262,-0.34202014,-311.11659,1246.6148)"
        transform="matrix(-0.34202014,-0.93969262,0.93969262,-0.34202014,-311.11659,1246.6148)"
        id="g5650-2-0-4-0"
        id="g5650-2-0-4-0"

+ 1 - 1
src/cowboy_rest.erl

@@ -780,7 +780,7 @@ process_content_type(Req, State=#state{method=Method, exists=Exists}, Fun) ->
 			next(Req2, State2, fun maybe_created/2);
 			next(Req2, State2, fun maybe_created/2);
 		{false, Req2, HandlerState2} ->
 		{false, Req2, HandlerState2} ->
 			State2 = State#state{handler_state=HandlerState2},
 			State2 = State#state{handler_state=HandlerState2},
-			respond(Req2, State2, 422);
+			respond(Req2, State2, 400);
 		{{true, ResURL}, Req2, HandlerState2} when Method =:= <<"POST">> ->
 		{{true, ResURL}, Req2, HandlerState2} when Method =:= <<"POST">> ->
 			State2 = State#state{handler_state=HandlerState2},
 			State2 = State#state{handler_state=HandlerState2},
 			Req3 = cowboy_req:set_resp_header(
 			Req3 = cowboy_req:set_resp_header(

+ 1 - 1
test/http_SUITE.erl

@@ -749,7 +749,7 @@ rest_options_default(Config) ->
 rest_patch(Config) ->
 rest_patch(Config) ->
 	Tests = [
 	Tests = [
 		{204, [{<<"content-type">>, <<"text/plain">>}], <<"whatever">>},
 		{204, [{<<"content-type">>, <<"text/plain">>}], <<"whatever">>},
-		{422, [{<<"content-type">>, <<"text/plain">>}], <<"false">>},
+		{400, [{<<"content-type">>, <<"text/plain">>}], <<"false">>},
 		{400, [{<<"content-type">>, <<"text/plain">>}], <<"halt">>},
 		{400, [{<<"content-type">>, <<"text/plain">>}], <<"halt">>},
 		{415, [{<<"content-type">>, <<"application/json">>}], <<"bad_content_type">>}
 		{415, [{<<"content-type">>, <<"application/json">>}], <<"bad_content_type">>}
 	],
 	],