Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove debug code and improve code estethic

  • Loading branch information...
commit f72811bc8332ec64d4e0394afa22d57c0f97ce29 1 parent 63cfb7e
@lafka authored
Showing with 14 additions and 23 deletions.
  1. +6 −12 src/tavern_http.erl
  2. +8 −11 src/tavern_req.erl
View
18 src/tavern_http.erl
@@ -50,15 +50,12 @@ init(_Transport, Req, [Handler]) ->
handle(Module, Req, #tavern{} = State) ->
try
case tavern_req:call(Req, State, fun tavern_req:client_acceptable/2) of
- %% Request is valid, pass it back to module for completion
{true, Req2, State2} ->
- {Status, Payload, Req3, State3} = handle_call(Module, Req2, State2),
- error_logger:info_msg("resp: call: ~p ~p~n", [Status, Payload]),
- handle_resp(Req3, State3, Status, Payload);
- %% tavern_req specifies return status
- {{Status, Payload}, Req2, State2} ->
- error_logger:info_msg("resp: direct: ~p ~p~n", [Status, Payload]),
- handle_resp(Req2, State2, Status, Payload)
+ {Status, NewReq, NewState, Payload} = handle_call(Module, Req2, State2),
+ handle_resp(NewReq, NewState, Status, Payload);
+ %% tavern_req specified return status
+ {{Status, Payload}, NewReq, NewState} ->
+ handle_resp(NewReq, NewState, Status, Payload)
end
catch
Class:Reason ->
@@ -80,8 +77,6 @@ terminate(_Handler, _Req, _State) ->
handle_call(Module, Req, #tavern{handlers = Handlers} = State) ->
{Method, Req} = cowboy_http_req:method(Req),
{Method, Handler} = lists:keyfind(Method, 1, Handlers),
- error_logger:info_msg("handler_list: ~p~nmethod: ~p~nhandler: ~p~n",
- [Handlers, Method, Handler]),
case erlang:function_exported(Module, Handler, 2) of
true -> Module:Handler(Req, State);
false -> erlang:error({no_export, Module, Handler})
@@ -96,7 +91,6 @@ handle_resp(Req, State, Status, Payload) when is_atom(Status) ->
handle_resp(Req, #tavern{accept = Accept} = State, Status, Payload) ->
try
{ok, EncodedPayload} = tavern_marshal:encode(Accept, Payload),
- error_logger:info_msg("abc: ~p~n", [EncodedPayload]),
A = cowboy_http_req:reply(Status, [], EncodedPayload, Req),
{ok, Resp} = A,
{ok, Resp, State}
@@ -109,7 +103,7 @@ handle_resp(Req, #tavern{accept = Accept} = State, Status, Payload) ->
"** stacktrace:~n~p~n",
[Module, Class, Reason, erlang:get_stacktrace()]),
{ok, Resp2} = cowboy_http_req:reply(status('Internal Server Error'),
- [], <<"(error #1001:) could write response">>,
+ [], <<"(error #1001:) could not write response">>,
Req),
{ok, Resp2, State}
end.
View
19 src/tavern_req.erl
@@ -87,7 +87,6 @@ consumed_type(Req, State) ->
{true, Req} ->
#tavern{consumes = TypeList} = State,
{Mime1, Mime2, Charset} = content_type(Req),
- error_logger:info_msg("eats: ~p - ~p~n", [{Mime1, Mime2, Charset}, TypeList]),
case match_media_type({Mime1, Mime2, Charset}, TypeList) of
[] ->
{ {'Not Acceptable', [
@@ -120,23 +119,21 @@ consumed_type(Req, State) ->
%% {true, Req, State}.
decode_body(Req, #tavern{content_type = ContentType} = State) ->
- error_logger:info_msg("decode_body: ~p~n", [ContentType]),
{ok, Binary} = cowboy_http_req:body(1500, Req),
Payload = tavern_marshal:decode(ContentType, Binary),
{true, Req, State#tavern{body = Payload}, success}.
call(Req, State, Fun) when is_function(Fun) ->
- case Fun(Req, State) of
- {true, Req2, State2, success} -> {true, Req2, State2};
- {true, Req2, State2, Next} -> call(Req2, State2, Next);
- {{_, _} = Result, Req2, State2} -> {Result, Req2, State2}
- end.
+ call(Req, State, Fun, success).
call(Req, State, Fun, Next) when is_function(Fun) ->
- case Fun(Req, State, Next) of
- {true, Req2, State2, success} -> {true, Req2, State2};
- {true, Req2, State2, Next2} -> call(Req2, State2, Next, Next2);
- {{_, _} = Result, Req2, State2} -> {Result, Req2, State2}
+ case Fun(Req, State) of
+ {true, Req2, State2, success} ->
+ {true, Req2, State2};
+ {true, Req2, State2, Next} ->
+ call(Req2, State2, Next);
+ {{_, _} = Result, Req2, State2} ->
+ {Result, Req2, State2}
end.
%% Private API
Please sign in to comment.
Something went wrong with that request. Please try again.