rabbit_db_vhost: Bubble up database errors in delete/1
We need to bubble up the error through the caller
`rabbit_vhost:delete/2`. The CLI calls `rabbit_vhost:delete/2` and
already handles the `{error, timeout}` but the management UI needs an
update so that an HTTP DELETE returns an error code when the deletion
times out.
This commit is contained in:
parent
2a86dde998
commit
83994501b5
|
|
@ -441,9 +441,10 @@ with_fun_in_khepri_tx(VHostName, Thunk) ->
|
|||
%% delete().
|
||||
%% -------------------------------------------------------------------
|
||||
|
||||
-spec delete(VHostName) -> Existed when
|
||||
-spec delete(VHostName) -> Ret when
|
||||
VHostName :: vhost:name(),
|
||||
Existed :: boolean().
|
||||
Existed :: boolean(),
|
||||
Ret :: Existed | rabbit_khepri:timeout_error().
|
||||
%% @doc Deletes a virtual host record from the database.
|
||||
%%
|
||||
%% @returns a boolean indicating if the vhost existed or not. It throws an
|
||||
|
|
@ -470,7 +471,7 @@ delete_in_khepri(VHostName) ->
|
|||
case rabbit_khepri:delete_or_fail(Path) of
|
||||
ok -> true;
|
||||
{error, {node_not_found, _}} -> false;
|
||||
_ -> false
|
||||
{error, _} = Err -> Err
|
||||
end.
|
||||
|
||||
%% -------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -287,7 +287,9 @@ delete(VHost, ActingUser) ->
|
|||
[{name, VHost},
|
||||
{user_who_performed_action, ActingUser}]);
|
||||
false ->
|
||||
{error, {no_such_vhost, VHost}}
|
||||
{error, {no_such_vhost, VHost}};
|
||||
{error, _} = Err ->
|
||||
Err
|
||||
end,
|
||||
%% After vhost was deleted from the database, we try to stop vhost
|
||||
%% supervisors on all the nodes.
|
||||
|
|
|
|||
|
|
@ -92,8 +92,22 @@ accept_content(ReqData0, Context = #context{user = #user{username = Username}})
|
|||
|
||||
delete_resource(ReqData, Context = #context{user = #user{username = Username}}) ->
|
||||
VHost = id(ReqData),
|
||||
_ = rabbit_vhost:delete(VHost, Username),
|
||||
{true, ReqData, Context}.
|
||||
case rabbit_vhost:delete(VHost, Username) of
|
||||
ok ->
|
||||
{true, ReqData, Context};
|
||||
{error, timeout} ->
|
||||
rabbit_mgmt_util:internal_server_error(
|
||||
timeout,
|
||||
"Timed out waiting for the vhost to be deleted",
|
||||
ReqData, Context);
|
||||
{error, E} ->
|
||||
Reason = iolist_to_binary(
|
||||
io_lib:format(
|
||||
"Error occurred while deleting vhost: ~tp",
|
||||
[E])),
|
||||
rabbit_mgmt_util:internal_server_error(
|
||||
Reason, ReqData, Context)
|
||||
end.
|
||||
|
||||
is_authorized(ReqData, Context) ->
|
||||
rabbit_mgmt_util:is_authorized_admin(ReqData, Context).
|
||||
|
|
|
|||
Loading…
Reference in New Issue