Browse Source

Make REST handlers' put_resource accept true or false return values

Followup to 0bb23f2400ed0b65834913c8522a978d986f1f92.
As discussed in #119.
Loïc Hoguin 13 years ago
parent
commit
fed6727634
1 changed files with 5 additions and 2 deletions
  1. 5 2
      src/cowboy_http_rest.erl

+ 5 - 2
src/cowboy_http_rest.erl

@@ -711,9 +711,12 @@ choose_content_type(Req, State, _OnTrue, _ContentType, []) ->
 choose_content_type(Req, State, OnTrue, ContentType,
 choose_content_type(Req, State, OnTrue, ContentType,
 		[{Accepted, Fun}|_Tail]) when ContentType =:= Accepted ->
 		[{Accepted, Fun}|_Tail]) when ContentType =:= Accepted ->
 	case call(Req, State, Fun) of
 	case call(Req, State, Fun) of
-		{ok, Req2, HandlerState} ->
+		{true, Req2, HandlerState} ->
+			State2 = State#state{handler_state=HandlerState},
+			next(Req2, State2, OnTrue);
+		{false, Req2, HandlerState} ->
 			State2 = State#state{handler_state=HandlerState},
 			State2 = State#state{handler_state=HandlerState},
-			next(Req2, State2, OnTrue)
+			respond(Req2, State2, 500)
 	end;
 	end;
 choose_content_type(Req, State, OnTrue, ContentType, [_Any|Tail]) ->
 choose_content_type(Req, State, OnTrue, ContentType, [_Any|Tail]) ->
 	choose_content_type(Req, State, OnTrue, ContentType, Tail).
 	choose_content_type(Req, State, OnTrue, ContentType, Tail).