Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/errors #31

Merged
merged 4 commits into from
Feb 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/kong/core/access.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function _M.execute(conf)
-- Retrieving the API from the Host that has been requested
local apis, err = dao.apis:find_by_keys({public_dns = stringy.split(ngx.var.http_host, ":")[1]})
if err then
ngx.log(ngx.ERR, err.message)
utils.show_error(500)
elseif not apis or #apis == 0 then
utils.not_found("API not found")
Expand Down
4 changes: 2 additions & 2 deletions src/kong/plugins/authentication/access.lua
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ function _M.execute(conf)
if public_key then
local applications, err = dao.applications:find_by_keys { public_key = public_key }
if err then
ngx.log(ngx.ERR, err)
return
ngx.log(ngx.ERR, err.message)
utils.show_error(500)
elseif #applications > 0 then
application = applications[1]
end
Expand Down
6 changes: 4 additions & 2 deletions src/kong/plugins/ratelimiting/access.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ function _M.execute(conf)
-- Load current metric for configured period
local current_metric, err = dao.metrics:find_one(ngx.ctx.api.id, identifier, current_timestamp, conf.period)
if err then
ngx.log(ngx.ERROR, err)
ngx.log(ngx.ERROR, err.message)
utils.show_error(500)
end

-- What is the current usage for the configured period?
Expand All @@ -38,7 +39,8 @@ function _M.execute(conf)
-- Increment metrics for all periods if the request goes through
local _, err = dao.metrics:increment(ngx.ctx.api.id, identifier, current_timestamp)
if err then
ngx.log(ngx.ERROR, err)
ngx.log(ngx.ERROR, err.message)
utils.show_error(500)
end
end

Expand Down
3 changes: 3 additions & 0 deletions src/kong/tools/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ end

function _M.show_error(status, message)
ngx.ctx.error = true
if not message then
message = "An error occurred"
end
_M.show_response(status, message)
end

Expand Down
3 changes: 1 addition & 2 deletions src/kong/web/routes/base_controller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ end

local function parse_dao_error(err)
local status

if err.database then
status = 500
ngx.log(ngx.ERR, err.message)
elseif err.unique then
status = 409
elseif err.foreign then
Expand All @@ -60,7 +60,6 @@ local function parse_dao_error(err)
else
status = 400
end

return utils.show_error(status, err.message)
end

Expand Down
2 changes: 1 addition & 1 deletion src/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ local function load_plugin_conf(api_id, application_id, plugin_name)

if err then
ngx.log(ngx.ERROR, err)
return nil
utils.show_error(500)
end

if #rows > 0 then
Expand Down