From 391eb55324c2cddc9addae5a3493109dde444ada Mon Sep 17 00:00:00 2001 From: Turtle Date: Thu, 12 Aug 2021 16:29:56 +0800 Subject: [PATCH] chore: format error log --- .../src/emqx_web_hook_actions.erl | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/apps/emqx_web_hook/src/emqx_web_hook_actions.erl b/apps/emqx_web_hook/src/emqx_web_hook_actions.erl index 2cbc53475..84e36ab0a 100644 --- a/apps/emqx_web_hook/src/emqx_web_hook_actions.erl +++ b/apps/emqx_web_hook/src/emqx_web_hook_actions.erl @@ -267,13 +267,13 @@ on_action_data_to_webserver(Selected, _Envs = {ok, StatusCode, _, _} when StatusCode >= 200 andalso StatusCode < 300 -> emqx_rule_metrics:inc_actions_success(Id); {ok, StatusCode, _} -> - ?LOG(warning, "[WebHook Action] HTTP request failed with status code: ~p", [StatusCode]), + ?LOG(warning, "HTTP request failed with path: ~p status code: ~p", [NPath, StatusCode]), emqx_rule_metrics:inc_actions_error(Id); {ok, StatusCode, _, _} -> - ?LOG(warning, "[WebHook Action] HTTP request failed with status code: ~p", [StatusCode]), + ?LOG(warning, "HTTP request failed with path: ~p status code: ~p", [NPath, StatusCode]), emqx_rule_metrics:inc_actions_error(Id); {error, Reason} -> - ?LOG(error, "[WebHook Action] HTTP request error: ~p", [Reason]), + ?LOG(error, "HTTP request failed path: ~p error: ~p", [NPath, Reason]), emqx_rule_metrics:inc_actions_error(Id) end. @@ -293,20 +293,16 @@ create_req(_, Path, Headers, Body) -> {Path, Headers, Body}. parse_action_params(Params = #{<<"url">> := URL}) -> - try - {ok, #{path := CommonPath}} = emqx_http_lib:uri_parse(URL), - Method = method(maps:get(<<"method">>, Params, <<"POST">>)), - Headers = headers(maps:get(<<"headers">>, Params, undefined)), - NHeaders = ensure_content_type_header(Headers, Method), - #{method => Method, - path => merge_path(CommonPath, maps:get(<<"path">>, Params, <<>>)), - headers => NHeaders, - body => maps:get(<<"body">>, Params, <<>>), - request_timeout => cuttlefish_duration:parse(str(maps:get(<<"request_timeout">>, Params, <<"5s">>))), - pool => maps:get(<<"pool">>, Params)} - catch _:_ -> - throw({invalid_params, Params}) - end. + {ok, #{path := CommonPath}} = emqx_http_lib:uri_parse(URL), + Method = method(maps:get(<<"method">>, Params, <<"POST">>)), + Headers = headers(maps:get(<<"headers">>, Params, undefined)), + NHeaders = ensure_content_type_header(Headers, Method), + #{method => Method, + path => merge_path(CommonPath, maps:get(<<"path">>, Params, <<>>)), + headers => NHeaders, + body => maps:get(<<"body">>, Params, <<>>), + request_timeout => cuttlefish_duration:parse(str(maps:get(<<"request_timeout">>, Params, <<"5s">>))), + pool => maps:get(<<"pool">>, Params)}. ensure_content_type_header(Headers, Method) when Method =:= post orelse Method =:= put -> Headers;