fix(bridge): mysql bridge error case

This commit is contained in:
JimMoen 2022-09-05 18:18:53 +08:00
parent 54a9c8d201
commit 0390a5e547
2 changed files with 22 additions and 2 deletions

View File

@ -532,6 +532,17 @@ lookup_from_local_node(BridgeType, BridgeName) ->
{200};
{error, timeout} ->
{503, error_msg('SERVICE_UNAVAILABLE', <<"request timeout">>)};
{error, {start_pool_failed, Name, Reason}} ->
{503,
error_msg(
'SERVICE_UNAVAILABLE',
bin(
io_lib:format(
"failed to start ~p pool for reason ~p",
[Name, Reason]
)
)
)};
{error, Reason} ->
{500, error_msg('INTERNAL_ERROR', Reason)}
end

View File

@ -40,12 +40,13 @@ start_pool(Name, Mod, Options) ->
stop_pool(Name),
start_pool(Name, Mod, Options);
{error, Reason} ->
NReason = parse_reason(Reason),
?SLOG(error, #{
msg => "start_ecpool_error",
pool_name => Name,
reason => Reason
reason => NReason
}),
{error, {start_pool_failed, Name, Reason}}
{error, {start_pool_failed, Name, NReason}}
end.
stop_pool(Name) ->
@ -86,3 +87,11 @@ health_check_ecpool_workers(PoolName, CheckFunc, Timeout) when is_function(Check
exit:timeout ->
false
end.
parse_reason({
{shutdown, {failed_to_start_child, _, {shutdown, {failed_to_start_child, _, Reason}}}},
_
}) ->
Reason;
parse_reason(Reason) ->
Reason.