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

spacewander 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 4ddeb4f  feat: refine admin API return JSON instead of code (#5174)
4ddeb4f is described below

commit 4ddeb4fdbe42cf1ee16162a97eb6a4329cce16a4
Author: zhendongcmss <[email protected]>
AuthorDate: Fri Oct 8 20:16:37 2021 +0800

    feat: refine admin API return JSON instead of code (#5174)
---
 apisix/admin/init.lua | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/apisix/admin/init.lua b/apisix/admin/init.lua
index e142c9d..f169d5a 100644
--- a/apisix/admin/init.lua
+++ b/apisix/admin/init.lua
@@ -124,7 +124,7 @@ local function run()
     local ok, err = check_token(api_ctx)
     if not ok then
         core.log.warn("failed to check token: ", err)
-        core.response.exit(401)
+        core.response.exit(401, {error_msg = "failed to check token"})
     end
 
     local uri_segs = core.utils.split_uri(ngx.var.uri)
@@ -141,12 +141,12 @@ local function run()
 
     local resource = resources[seg_res]
     if not resource then
-        core.response.exit(404)
+        core.response.exit(404, {error_msg = "not found"})
     end
 
     local method = str_lower(get_method())
     if not resource[method] then
-        core.response.exit(404)
+        core.response.exit(404, {error_msg = "not found"})
     end
 
     local req_body, err = core.request.get_body(MAX_REQ_BODY)
@@ -190,15 +190,15 @@ local function run_stream()
 
     local local_conf = core.config.local_conf()
     if not local_conf.apisix.stream_proxy then
-        core.log.warn("stream mode is disabled, can not to add any stream ",
-                      "route")
-        core.response.exit(400)
+        core.log.warn("stream mode is disabled, can not add any stream ",
+                      "routes")
+        core.response.exit(400, {error_msg = "stream mode is disabled, " ..
+                                             "can not add stream routes"})
     end
 
     local ok, err = check_token(api_ctx)
     if not ok then
         core.log.warn("failed to check token: ", err)
-        core.response.exit(401)
     end
 
     local uri_segs = core.utils.split_uri(ngx.var.uri)
@@ -215,12 +215,12 @@ local function run_stream()
 
     local resource = resources[seg_res]
     if not resource then
-        core.response.exit(404)
+        core.response.exit(404, {error_msg = "not found"})
     end
 
     local method = str_lower(get_method())
     if not resource[method] then
-        core.response.exit(404)
+        core.response.exit(404, {error_msg = "not found"})
     end
 
     req_read_body()
@@ -262,7 +262,7 @@ local function get_plugins_list()
     local ok, err = check_token(api_ctx)
     if not ok then
         core.log.warn("failed to check token: ", err)
-        core.response.exit(401)
+        core.response.exit(401, {error_msg = "failed to check token"})
     end
 
     local plugins = resources.plugins.get_plugins_list()
@@ -278,7 +278,7 @@ local function post_reload_plugins()
     local ok, err = check_token(api_ctx)
     if not ok then
         core.log.warn("failed to check token: ", err)
-        core.response.exit(401)
+        core.response.exit(401, {error_msg = "failed to check token"})
     end
 
     local success, err = events.post(reload_event, get_method(), ngx_time())

Reply via email to