Skip to content

Commit

Permalink
fix: correct response structure when api-gateway error, issue Tencent…
Browse files Browse the repository at this point in the history
  • Loading branch information
DeveloperJim committed Apr 29, 2020
1 parent e826cf5 commit defcb58
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bcs-services/bcs-gateway-discovery/bkbcs-auth/bkbcs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ end
--* @return: ip, port, error if happened
function BKUserCli:instance_balancer(key)
if key then
userTarget.hostname = key
userTarget.host = key
end
local ok, msg, code = kongBalancer.execute(userTarget)
if not ok then
Expand Down
8 changes: 4 additions & 4 deletions bcs-services/bcs-gateway-discovery/bkbcs-auth/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ function BKBCSAuthHandler:access(conf)
if err then
kong.log.err("init user-manager client with endpoint [", conf.bkbcs_auth_endpoints, "] failed: ", err)
-- response internal error
return kong.response.exit(500, {message = "An unexpected error occurred when authentication"})
return kong.response.exit(500, {code = 400, result = false, message = "An unexpected error occurred when authentication"})
end
-- construct request according configuration
local req, err = userc:construct_identity(conf, kong.request)
if err then
kong.log.err("construct auth request for [", kong.request.get_method(), "]", kong.request.get_path(), ", err:", err)
return kong.response.exit(400, {message = "Bad Request: " .. err})
return kong.response.exit(400, {code = 400, result = false, message = "Bad Request: " .. err})
end
-- init success, try to anthentication
local ok, err = userc:authentication(conf, req)
if err then
return kong.response.exit(500, {message = "An unexpected error occurred in verify: " .. err})
return kong.response.exit(500, {code = 500, result = false, message = "An unexpected error occurred in verify: " .. err})
end
if not ok then
kong.log.warn("token is not allow to access to [", kong.request.get_method(), "]", kong.request.get_path())
return kong.response.exit(401, {message = "Resource is Unauthorized"})
return kong.response.exit(401, {code = 401, result = false, message = "Resource is Unauthorized"})
end
end

Expand Down

0 comments on commit defcb58

Please sign in to comment.