add debug

This commit is contained in:
anlicheng 2026-04-27 16:29:03 +08:00
parent 9f5ad1c646
commit 15264e9e6c

View File

@ -19,10 +19,12 @@ init(Req0, Opts = [Mod|_]) ->
GetParams = maps:from_list(GetParams0), GetParams = maps:from_list(GetParams0),
{ok, PostParams, Req1} = parse_body(Req0), {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 try Mod:handle_request(Method, Path, GetParams, PostParams) of
{ok, StatusCode, Resp} -> {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, <<>>), AcceptEncoding = cowboy_req:header(<<"accept-encoding">>, Req1, <<>>),
Req2 = case iolist_size(Resp) >= 1024 andalso supported_gzip(AcceptEncoding) of Req2 = case iolist_size(Resp) >= 1024 andalso supported_gzip(AcceptEncoding) of
true -> true ->
@ -45,9 +47,10 @@ init(Req0, Opts = [Mod|_]) ->
{ok, Req2, Opts}; {ok, Req2, Opts};
_:Error:Stack -> _:Error:Stack ->
logger:warning("[http_handler] get error: ~p, stack: ~p", [Error, Stack]), logger:warning("[http_handler] get error: ~p, stack: ~p", [Error, Stack]),
ErrorBin = term_to_binary(Error),
Req2 = cowboy_req:reply(500, #{ Req2 = cowboy_req:reply(500, #{
<<"Content-Type">> => <<"text/html;charset=utf-8">> <<"Content-Type">> => <<"text/html;charset=utf-8">>
}, <<"Internal Server Error">>, Req1), }, <<"Internal Server Error: ", ErrorBin/binary>>, Req1),
{ok, Req2, Opts} {ok, Req2, Opts}
end. end.