fix(emqx_retainer): return 404 in delete if topic not found

This commit is contained in:
Stefan Strigler 2023-07-07 13:31:57 +02:00
parent 80e4ffff75
commit 1110b5d8f5
3 changed files with 13 additions and 3 deletions

View File

@ -2,7 +2,7 @@
{application, emqx_retainer, [
{description, "EMQX Retainer"},
% strict semver, bump manually!
{vsn, "5.0.14"},
{vsn, "5.0.15"},
{modules, []},
{registered, [emqx_retainer_sup]},
{applications, [kernel, stdlib, emqx, emqx_ctl]},

View File

@ -102,6 +102,7 @@ schema(?PREFIX ++ "/message/:topic") ->
parameters => parameters(),
responses => #{
204 => <<>>,
404 => error_codes(['NOT_FOUND'], ?DESC(message_not_exist)),
400 => error_codes(
['BAD_REQUEST'],
?DESC(unsupported_backend)
@ -187,8 +188,16 @@ with_topic(get, #{bindings := Bindings}) ->
end;
with_topic(delete, #{bindings := Bindings}) ->
Topic = maps:get(topic, Bindings),
emqx_retainer_mnesia:delete_message(undefined, Topic),
{204}.
case emqx_retainer_mnesia:page_read(undefined, Topic, 1, 1) of
{ok, []} ->
{404, #{
code => <<"NOT_FOUND">>,
message => <<"Viewed message doesn't exist">>
}};
{ok, _} ->
emqx_retainer_mnesia:delete_message(undefined, Topic),
{204}
end.
format_message(#message{
id = ID,

View File

@ -218,6 +218,7 @@ t_lookup_and_delete(_) ->
{ok, []} = request_api(delete, API),
{error, {"HTTP/1.1", 404, "Not Found"}} = request_api(get, API),
{error, {"HTTP/1.1", 404, "Not Found"}} = request_api(delete, API),
ok = emqtt:disconnect(C1).