fix(delayed): fix http 500 error

This commit is contained in:
JianBo He 2024-01-11 10:36:55 +08:00
parent b16920e796
commit eea0ec135f
2 changed files with 25 additions and 0 deletions

View File

@ -329,6 +329,12 @@ generate_http_code_map(message_not_found, Topic) ->
message =>
iolist_to_binary(io_lib:format("Not found messages for ~s", [Topic]))
};
generate_http_code_map(invalid_topic_name, Topic) ->
#{
code => ?INVALID_TOPIC,
message =>
iolist_to_binary(io_lib:format("The topic name ~s is invalid", [Topic]))
};
generate_http_code_map(invalid_node, Node) ->
#{
code => ?INVALID_NODE,

View File

@ -211,6 +211,25 @@ t_delete_messages_via_topic(_) ->
%% assert: messages are deleted
?assertEqual([], get_messages(0)),
%% assert: return 400 if the topic parameter is invalid
TopicFilter = uri_string:quote(<<"t/#">>),
?assertMatch(
{ok, 400, _},
request(
delete,
uri(["mqtt", "delayed", "messages", TopicFilter])
)
),
%% assert: return 404 if no messages found for the topic
?assertMatch(
{ok, 404, _},
request(
delete,
uri(["mqtt", "delayed", "messages", TopicInUrl])
)
),
ok.
t_large_payload(_) ->