mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-22 17:28:25 +01:00
Remove logging from REST lib
This commit is contained in:
parent
25f7ce0cb6
commit
492da2baac
29
src/rest.erl
29
src/rest.erl
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
-export([start/1, stop/1, get/2, get/3, post/4, delete/2,
|
-export([start/1, stop/1, get/2, get/3, post/4, delete/2,
|
||||||
put/4, patch/4, request/6, with_retry/4,
|
put/4, patch/4, request/6, with_retry/4,
|
||||||
encode_json/1, opt_type/1]).
|
opt_type/1]).
|
||||||
|
|
||||||
-include("logger.hrl").
|
-include("logger.hrl").
|
||||||
|
|
||||||
@ -79,6 +79,10 @@ patch(Server, Path, Params, Content) ->
|
|||||||
Data = encode_json(Content),
|
Data = encode_json(Content),
|
||||||
request(Server, patch, Path, Params, ?CONTENT_TYPE, Data).
|
request(Server, patch, Path, Params, ?CONTENT_TYPE, Data).
|
||||||
|
|
||||||
|
request(Server, Method, Path, _Params, _Mime, {error, Error}) ->
|
||||||
|
ejabberd_hooks:run(backend_api_error, Server,
|
||||||
|
[Server, Method, Path, Error]);
|
||||||
|
{error, Error};
|
||||||
request(Server, Method, Path, Params, Mime, Data) ->
|
request(Server, Method, Path, Params, Mime, Data) ->
|
||||||
{Query, Opts} = case Params of
|
{Query, Opts} = case Params of
|
||||||
{_, _} -> Params;
|
{_, _} -> Params;
|
||||||
@ -107,26 +111,13 @@ request(Server, Method, Path, Params, Mime, Data) ->
|
|||||||
false -> {ok, Code, JSon}
|
false -> {ok, Code, JSon}
|
||||||
end
|
end
|
||||||
catch
|
catch
|
||||||
_:Error ->
|
_:Reason ->
|
||||||
?ERROR_MSG("HTTP response decode failed:~n"
|
{error, {invalid_json, Body, Reason}}
|
||||||
"** URI = ~s~n"
|
|
||||||
"** Body = ~p~n"
|
|
||||||
"** Err = ~p",
|
|
||||||
[URI, Body, Error]),
|
|
||||||
{error, {invalid_json, Body}}
|
|
||||||
end;
|
end;
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?ERROR_MSG("HTTP request failed:~n"
|
|
||||||
"** URI = ~s~n"
|
|
||||||
"** Err = ~p",
|
|
||||||
[URI, Reason]),
|
|
||||||
{error, {http_error, {error, Reason}}}
|
{error, {http_error, {error, Reason}}}
|
||||||
catch
|
catch
|
||||||
exit:Reason ->
|
exit:Reason ->
|
||||||
?ERROR_MSG("HTTP request failed:~n"
|
|
||||||
"** URI = ~s~n"
|
|
||||||
"** Err = ~p",
|
|
||||||
[URI, Reason]),
|
|
||||||
{error, {http_error, {error, Reason}}}
|
{error, {http_error, {error, Reason}}}
|
||||||
end,
|
end,
|
||||||
ejabberd_hooks:run(backend_api_call, Server, [Server, Method, Path]),
|
ejabberd_hooks:run(backend_api_call, Server, [Server, Method, Path]),
|
||||||
@ -137,9 +128,9 @@ request(Server, Method, Path, Params, Mime, Data) ->
|
|||||||
{error, {http_error, {error, connect_timeout}}} ->
|
{error, {http_error, {error, connect_timeout}}} ->
|
||||||
ejabberd_hooks:run(backend_api_timeout, Server,
|
ejabberd_hooks:run(backend_api_timeout, Server,
|
||||||
[Server, Method, Path]);
|
[Server, Method, Path]);
|
||||||
{error, _} ->
|
{error, Error} ->
|
||||||
ejabberd_hooks:run(backend_api_error, Server,
|
ejabberd_hooks:run(backend_api_error, Server,
|
||||||
[Server, Method, Path]);
|
[Server, Method, Path, Error]);
|
||||||
_ ->
|
_ ->
|
||||||
End = os:timestamp(),
|
End = os:timestamp(),
|
||||||
Elapsed = timer:now_diff(End, Begin) div 1000, %% time in ms
|
Elapsed = timer:now_diff(End, Begin) div 1000, %% time in ms
|
||||||
@ -164,7 +155,7 @@ encode_json(Content) ->
|
|||||||
"** Content = ~p~n"
|
"** Content = ~p~n"
|
||||||
"** Err = ~p",
|
"** Err = ~p",
|
||||||
[Content, Reason]),
|
[Content, Reason]),
|
||||||
<<>>;
|
{error, {invalid_payload, Content, Reason}};
|
||||||
Encoded ->
|
Encoded ->
|
||||||
Encoded
|
Encoded
|
||||||
end.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user