Forráskód Böngészése

fix(emqx_management): return 404 if plugin does not exist

Stefan Strigler 2 éve
szülő
commit
80e4ffff75

+ 3 - 0
apps/emqx_management/src/emqx_mgmt_api_plugins.erl

@@ -132,6 +132,7 @@ schema("/plugins/:name") ->
             parameters => [hoconsc:ref(name)],
             responses => #{
                 204 => <<"Uninstall successfully">>,
+                400 => emqx_dashboard_swagger:error_codes(['PARAM_ERROR'], <<"Bad parameter">>),
                 404 => emqx_dashboard_swagger:error_codes(['NOT_FOUND'], <<"Plugin Not Found">>)
             }
         }
@@ -484,6 +485,8 @@ ensure_action(Name, restart) ->
 
 return(Code, ok) ->
     {Code};
+return(_, {error, #{error := "bad_info_file", return := {enoent, _} = Reason}}) ->
+    {404, #{code => 'NOT_FOUND', message => iolist_to_binary(io_lib:format("~p", [Reason]))}};
 return(_, {error, Reason}) ->
     {400, #{code => 'PARAM_ERROR', message => iolist_to_binary(io_lib:format("~p", [Reason]))}}.
 

+ 8 - 0
apps/emqx_management/test/emqx_mgmt_api_plugins_SUITE.erl

@@ -133,6 +133,14 @@ t_bad_plugin(Config) ->
         )
     ).
 
+t_delete_non_existing(_Config) ->
+    Path = emqx_mgmt_api_test_util:api_path(["plugins", "non_exists"]),
+    ?assertMatch(
+        {error, {_, 404, _}},
+        emqx_mgmt_api_test_util:request_api(delete, Path)
+    ),
+    ok.
+
 list_plugins() ->
     Path = emqx_mgmt_api_test_util:api_path(["plugins"]),
     case emqx_mgmt_api_test_util:request_api(get, Path) of