aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2012-01-06 21:05:58 +0100
committerLoïc Hoguin <[email protected]>2012-01-06 21:05:58 +0100
commit0bb23f2400ed0b65834913c8522a978d986f1f92 (patch)
treec4352e76f9bcd7994a7b1bc06aa98168196255c9
parentd2f13366a9663a7facac7ad6d621d5131e778e28 (diff)
downloadcowboy-0bb23f2400ed0b65834913c8522a978d986f1f92.tar.gz
cowboy-0bb23f2400ed0b65834913c8522a978d986f1f92.tar.bz2
cowboy-0bb23f2400ed0b65834913c8522a978d986f1f92.zip
Make REST handlers' process_post accept true or false return values
They should return true when it has been processed successfully, or false otherwise, in which case a 500 error is sent. Fixes #119.
-rw-r--r--src/cowboy_http_rest.erl9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/cowboy_http_rest.erl b/src/cowboy_http_rest.erl
index a5333fe..63d15ff 100644
--- a/src/cowboy_http_rest.erl
+++ b/src/cowboy_http_rest.erl
@@ -668,11 +668,16 @@ create_path_location_port(tcp, 80) ->
create_path_location_port(_, Port) ->
<<":", (list_to_binary(integer_to_list(Port)))/binary>>.
+%% process_post should return true when the POST body could be processed
+%% and false when it hasn't, in which case a 500 error is sent.
process_post(Req, State) ->
case call(Req, State, process_post) of
- {ok, Req2, HandlerState} ->
+ {true, Req2, HandlerState} ->
+ State2 = State#state{handler_state=HandlerState},
+ next(Req2, State2, 201);
+ {false, Req2, HandlerState} ->
State2 = State#state{handler_state=HandlerState},
- next(Req2, State2, 201)
+ respond(Req2, State2, 500)
end.
is_conflict(Req, State) ->