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

fix: generate bridge api response code

fix: generate connector api response code SUITE

fix: generate exhook api response code
DDDHuang 3 лет назад
Родитель
Сommit
74e6fa5a94

+ 2 - 0
apps/emqx/include/http_api.hrl

@@ -30,6 +30,7 @@
 -define(NO_DEFAULT_VALUE,         'NO_DEFAULT_VALUE').
 -define(DEPENDENCY_EXISTS,        'DEPENDENCY_EXISTS').
 -define(MESSAGE_ID_SCHEMA_ERROR,  'MESSAGE_ID_SCHEMA_ERROR').
+-define(INVALID_ID,               'INVALID_ID').
 
 %% Resource Not Found
 -define(NOT_FOUND,                'NOT_FOUND').
@@ -63,6 +64,7 @@
     , {'NO_DEFAULT_VALUE',          <<"Request parameters do not use default values">>}
     , {'DEPENDENCY_EXISTS',         <<"Resource is dependent by another resource">>}
     , {'MESSAGE_ID_SCHEMA_ERROR',   <<"Message ID parsing error">>}
+    , {'INVALID_ID',                <<"Bad ID schema">>}
     , {'MESSAGE_ID_NOT_FOUND',      <<"Message ID does not exist">>}
     , {'NOT_FOUND',                 <<"Resource was not found or does not exist">>}
     , {'CLIENTID_NOT_FOUND',        <<"Client ID was not found or does not exist">>}

+ 7 - 6
apps/emqx_bridge/src/emqx_bridge_api.erl

@@ -267,7 +267,7 @@ schema("/bridges/:id") ->
             responses => #{
                 200 => get_response_body_schema(),
                 404 => error_schema('NOT_FOUND', "Bridge not found"),
-                400 => error_schema('BAD_REQUEST', "Update bridge failed")
+                400 => error_schema(['BAD_REQUEST', 'INVALID_ID'], "Update bridge failed")
             }
         },
         delete => #{
@@ -276,7 +276,8 @@ schema("/bridges/:id") ->
             description => <<"Delete a bridge by Id">>,
             parameters => [param_path_id()],
             responses => #{
-                204 => <<"Bridge deleted">>
+                204 => <<"Bridge deleted">>,
+                400 => error_schema(['INVALID_ID'], "Update bridge failed")
             }
         }
     };
@@ -294,8 +295,8 @@ schema("/bridges/:id/operation/:operation") ->
                 param_path_operation_cluster()
             ],
             responses => #{
-                500 => error_schema('INTERNAL_ERROR', "Operation Failed"),
-                200 => <<"Operation success">>
+                200 => <<"Operation success">>,
+                400 => error_schema('INVALID_ID', "Bad bridge ID")
             }
         }
     };
@@ -314,8 +315,8 @@ schema("/nodes/:node/bridges/:id/operation/:operation") ->
                 param_path_operation_on_node()
             ],
             responses => #{
-                500 => error_schema('INTERNAL_ERROR', "Operation Failed"),
-                200 => <<"Operation success">>
+                200 => <<"Operation success">>,
+                400 => error_schema('INVALID_ID', "Bad bridge ID")
             }
         }
     }.

+ 6 - 3
apps/emqx_connector/src/emqx_connector_api.erl

@@ -171,7 +171,8 @@ schema("/connectors/:id") ->
             parameters => param_path_id(),
             responses => #{
                 200 => get_response_body_schema(),
-                404 => error_schema(['NOT_FOUND'], "Connector not found")
+                404 => error_schema(['NOT_FOUND'], "Connector not found"),
+                400 => error_schema(['INVALID_ID'], "Bad connector ID")
             }
         },
         put => #{
@@ -182,7 +183,8 @@ schema("/connectors/:id") ->
             'requestBody' => put_request_body_schema(),
             responses => #{
                 200 => get_response_body_schema(),
-                404 => error_schema(['NOT_FOUND'], "Connector not found")
+                404 => error_schema(['NOT_FOUND'], "Connector not found"),
+                400 => error_schema(['INVALID_ID'], "Bad connector ID")
             }},
         delete => #{
             tags => [<<"connectors">>],
@@ -192,7 +194,8 @@ schema("/connectors/:id") ->
             responses => #{
                 204 => <<"Delete connector successfully">>,
                 403 => error_schema(['DEPENDENCY_EXISTS'], "Cannot remove dependent connector"),
-                404 => error_schema(['NOT_FOUND'], "Delete failed, not found")
+                404 => error_schema(['NOT_FOUND'], "Delete failed, not found"),
+                400 => error_schema(['INVALID_ID'], "Bad connector ID")
             }}
     }.
 

+ 6 - 5
apps/emqx_dashboard/src/emqx_dashboard.erl

@@ -92,11 +92,12 @@ stop_listeners() ->
 %% internal
 
 apps() ->
-    [App || {App, _, _} <- application:loaded_applications(),
-        case re:run(atom_to_list(App), "^emqx") of
-            {match,[{0,4}]} -> true;
-            _ -> false
-        end].
+    [emqx_exhook].
+    % [App || {App, _, _} <- application:loaded_applications(),
+    %     case re:run(atom_to_list(App), "^emqx") of
+    %         {match,[{0,4}]} -> true;
+    %         _ -> false
+    %     end].
 
 listeners() ->
     [begin

+ 0 - 1
apps/emqx_exhook/src/emqx_exhook_api.erl

@@ -241,7 +241,6 @@ move(post, #{bindings := #{name := Name}, body := #{<<"position">> := RawPositio
                 {ok, ok} ->
                     {204};
                 {ok, not_found} ->
-                    %% TODO: unify status code
                     {400, #{code => <<"BAD_REQUEST">>,
                             message => <<"Server not found">>
                            }};