Skip to content

Commit

Permalink
Use different not_found msg for vhosts & resources
Browse files Browse the repository at this point in the history
  • Loading branch information
LoisSotoLopez committed Apr 10, 2024
1 parent 0b4fff9 commit 383ddb1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 15 deletions.
19 changes: 14 additions & 5 deletions deps/rabbitmq_management/src/rabbit_mgmt_wm_exchange_publish.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,12 @@ content_types_provided(ReqData, Context) ->

resource_exists(ReqData, Context) ->
{case rabbit_mgmt_wm_exchange:exchange(ReqData) of
not_found -> false;
not_found -> raise_not_found(ReqData, Context);
_ -> true
end, ReqData, Context}.

allow_missing_post(ReqData, Context) ->
rabbit_mgmt_util:not_found(
rabbit_data_coercion:to_binary("vhost_not_found"),
ReqData,
Context).
{false, ReqData, Context}.

content_types_accepted(ReqData, Context) ->
{[{'*', accept_content}], ReqData, Context}.
Expand Down Expand Up @@ -107,6 +104,18 @@ bad({{coordinator_unavailable, _}, _}, ReqData, Context) ->
is_authorized(ReqData, Context) ->
rabbit_mgmt_util:is_authorized_vhost(ReqData, Context).

raise_not_found(ReqData, Context) ->
ErrorMessage = case rabbit_mgmt_util:vhost(ReqData) of
not_found ->
"vhost_not_found";
_ ->
"exchange_not_found"
end,
rabbit_mgmt_util:not_found(
rabbit_data_coercion:to_binary(ErrorMessage),
ReqData,
Context).

%%--------------------------------------------------------------------

decode(Payload, <<"string">>) -> Payload;
Expand Down
18 changes: 13 additions & 5 deletions deps/rabbitmq_management/src/rabbit_mgmt_wm_queue_actions.erl
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,12 @@ allowed_methods(ReqData, Context) ->

resource_exists(ReqData, Context) ->
{case rabbit_mgmt_wm_queue:queue(ReqData) of
not_found -> false;
not_found -> raise_not_found(ReqData, Context);
_ -> true
end, ReqData, Context}.

allow_missing_post(ReqData, Context) ->
rabbit_mgmt_util:not_found(
rabbit_data_coercion:to_binary("vhost_not_found"),
ReqData,
Context).
{false, ReqData, Context}.

content_types_accepted(ReqData, Context) ->
{[{'*', accept_content}], ReqData, Context}.
Expand All @@ -58,6 +55,17 @@ do_it(ReqData0, Context) ->
is_authorized(ReqData, Context) ->
rabbit_mgmt_util:is_authorized_admin(ReqData, Context).

raise_not_found(ReqData, Context) ->
ErrorMessage = case rabbit_mgmt_util:vhost(ReqData) of
not_found ->
"vhost_not_found";
_ ->
"queue_not_found"
end,
rabbit_mgmt_util:not_found(
rabbit_data_coercion:to_binary(ErrorMessage),
ReqData,
Context).
%%--------------------------------------------------------------------

action(<<"sync">>, Q, ReqData, Context) when ?is_amqqueue(Q) ->
Expand Down
18 changes: 13 additions & 5 deletions deps/rabbitmq_management/src/rabbit_mgmt_wm_queue_get.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,12 @@ content_types_provided(ReqData, Context) ->

resource_exists(ReqData, Context) ->
{case rabbit_mgmt_wm_queue:queue(ReqData) of
not_found -> false;
not_found -> raise_not_found(ReqData, Context);
_ -> true
end, ReqData, Context}.

allow_missing_post(ReqData, Context) ->
rabbit_mgmt_util:not_found(
rabbit_data_coercion:to_binary("vhost_not_found"),
ReqData,
Context).
{false, ReqData, Context}.

content_types_accepted(ReqData, Context) ->
{[{'*', accept_content}], ReqData, Context}.
Expand Down Expand Up @@ -155,6 +152,17 @@ basic_get(Ch, Q, AckMode, Enc, Trunc) ->
is_authorized(ReqData, Context) ->
rabbit_mgmt_util:is_authorized_vhost(ReqData, Context).

raise_not_found(ReqData, Context) ->
ErrorMessage = case rabbit_mgmt_util:vhost(ReqData) of
not_found ->
"vhost_not_found";
_ ->
"queue_not_found"
end,
rabbit_mgmt_util:not_found(
rabbit_data_coercion:to_binary(ErrorMessage),
ReqData,
Context).
%%--------------------------------------------------------------------

maybe_truncate(Payload, none) -> Payload;
Expand Down

0 comments on commit 383ddb1

Please sign in to comment.