This is an automated email from the ASF dual-hosted git repository.

monkeydluffy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 34e3f767a refactor: return concise error when invalid resource is used 
(#9574)
34e3f767a is described below

commit 34e3f767ab7516935dfd27d4d4bb9d25f5900cdc
Author: Abhishek Choudhary <[email protected]>
AuthorDate: Thu Jun 15 08:08:18 2023 +0530

    refactor: return concise error when invalid resource is used (#9574)
---
 apisix/admin/init.lua |  2 +-
 t/admin/resources.t   | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 1 deletion(-)

diff --git a/apisix/admin/init.lua b/apisix/admin/init.lua
index 2ab266bb9..412e15447 100644
--- a/apisix/admin/init.lua
+++ b/apisix/admin/init.lua
@@ -184,7 +184,7 @@ local function run()
 
     local resource = resources[seg_res]
     if not resource then
-        core.response.exit(404, {error_msg = "not found"})
+        core.response.exit(404, {error_msg = "Unsupported resource type: ".. 
seg_res})
     end
 
     local method = str_lower(get_method())
diff --git a/t/admin/resources.t b/t/admin/resources.t
new file mode 100644
index 000000000..e1f39ccc0
--- /dev/null
+++ b/t/admin/resources.t
@@ -0,0 +1,55 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+no_long_string();
+no_root_location();
+no_shuffle();
+log_level("info");
+
+run_tests;
+
+__DATA__
+
+=== TEST 1: invalid resource type: 'routs'
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/routs/1',
+                ngx.HTTP_PUT,
+                [[{
+                    "methods": ["GET"],
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.1:8080": 1
+                        },
+                        "type": "roundrobin"
+                    },
+                    "desc": "new route",
+                    "uri": "/index.html"
+                }]]
+                )
+
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body_like
+{"error_msg":"Unsupported resource type: routs"}

Reply via email to