Просмотр исходного кода

fix(delayed): fix http 500 error

JianBo He 2 лет назад
Родитель
Сommit
eea0ec135f

+ 6 - 0
apps/emqx_modules/src/emqx_delayed_api.erl

@@ -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,

+ 19 - 0
apps/emqx_modules/test/emqx_delayed_api_SUITE.erl

@@ -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(_) ->