feat: make http connector report errors

This commit is contained in:
Stefan Strigler 2023-01-11 15:11:41 +01:00
parent 77f043dedf
commit 04f46f5227
1 changed files with 17 additions and 12 deletions

View File

@ -384,14 +384,15 @@ on_query_async(
on_get_status(_InstId, #{pool_name := PoolName, connect_timeout := Timeout} = State) ->
case do_get_status(PoolName, Timeout) of
true ->
connected;
false ->
ok ->
{connected, State};
{error, Reason} ->
?SLOG(error, #{
msg => "http_connector_get_status_failed",
reason => Reason,
state => State
}),
disconnected
{disconnected, State, Reason}
end.
do_get_status(PoolName, Timeout) ->
@ -400,24 +401,28 @@ do_get_status(PoolName, Timeout) ->
fun(Worker) ->
case ehttpc:health_check(Worker, Timeout) of
ok ->
true;
{error, Reason} ->
ok;
{error, Reason} = Error ->
?SLOG(error, #{
msg => "ehttpc_health_check_failed",
reason => Reason,
worker => Worker
}),
false
Error
end
end,
try emqx_misc:pmap(DoPerWorker, Workers, Timeout) of
[_ | _] = Status ->
lists:all(fun(St) -> St =:= true end, Status);
% we crash in case of non-empty lists since we don't know what to do in that case
[_ | _] = Results ->
case [E || {error, _} = E <- Results] of
[] ->
false
ok;
Errors ->
hd(Errors)
end
catch
exit:timeout ->
false
{error, timeout}
end.
%%--------------------------------------------------------------------