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