add debug
This commit is contained in:
parent
9f5ad1c646
commit
15264e9e6c
@ -19,10 +19,12 @@ init(Req0, Opts = [Mod|_]) ->
|
||||
GetParams = maps:from_list(GetParams0),
|
||||
{ok, PostParams, Req1} = parse_body(Req0),
|
||||
|
||||
Headers = cowboy_req:headers(Req0),
|
||||
logger:debug("[http_protocol] request path: ~p, get_params: ~p, post_params: ~p, headers: ~p",
|
||||
[Path, GetParams, PostParams, Headers]),
|
||||
|
||||
try Mod:handle_request(Method, Path, GetParams, PostParams) of
|
||||
{ok, StatusCode, Resp} ->
|
||||
logger:debug("[http_protocol] request path: ~p, get_params: ~p, post_params: ~p, response: ~ts",
|
||||
[Path, GetParams, PostParams, Resp]),
|
||||
AcceptEncoding = cowboy_req:header(<<"accept-encoding">>, Req1, <<>>),
|
||||
Req2 = case iolist_size(Resp) >= 1024 andalso supported_gzip(AcceptEncoding) of
|
||||
true ->
|
||||
@ -45,9 +47,10 @@ init(Req0, Opts = [Mod|_]) ->
|
||||
{ok, Req2, Opts};
|
||||
_:Error:Stack ->
|
||||
logger:warning("[http_handler] get error: ~p, stack: ~p", [Error, Stack]),
|
||||
ErrorBin = term_to_binary(Error),
|
||||
Req2 = cowboy_req:reply(500, #{
|
||||
<<"Content-Type">> => <<"text/html;charset=utf-8">>
|
||||
}, <<"Internal Server Error">>, Req1),
|
||||
}, <<"Internal Server Error: ", ErrorBin/binary>>, Req1),
|
||||
{ok, Req2, Opts}
|
||||
end.
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user