Skip to content

Commit

Permalink
Make REST handlers' process_post accept true or false return values
Browse files Browse the repository at this point in the history
They should return true when it has been processed successfully,
or false otherwise, in which case a 500 error is sent.

Fixes ninenines#119.
  • Loading branch information
Loïc Hoguin committed Jan 6, 2012
1 parent d2f1336 commit 0bb23f2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/cowboy_http_rest.erl
Expand Up @@ -668,11 +668,16 @@ create_path_location_port(tcp, 80) ->
create_path_location_port(_, Port) -> create_path_location_port(_, Port) ->
<<":", (list_to_binary(integer_to_list(Port)))/binary>>. <<":", (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) -> process_post(Req, State) ->
case call(Req, State, process_post) of 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}, State2 = State#state{handler_state=HandlerState},
next(Req2, State2, 201) respond(Req2, State2, 500)
end. end.


is_conflict(Req, State) -> is_conflict(Req, State) ->
Expand Down

0 comments on commit 0bb23f2

Please sign in to comment.