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(db) kong.db.errors module did not receive name of the strategy #3612

Merged
merged 1 commit into from
Jul 13, 2018
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
10 changes: 10 additions & 0 deletions kong/api/endpoints.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ local app_helpers = require "lapis.application"

local escape_uri = ngx.escape_uri
local unescape_uri = ngx.unescape_uri
local tostring = tostring
local null = ngx.null
local type = type
local fmt = string.format


Expand All @@ -25,6 +27,14 @@ local ERRORS_HTTP_CODES = {


local function handle_error(err_t)
if type(err_t) ~= "table" then
responses.send(500, tostring(err_t))
end

if err_t.strategy then
err_t.strategy = nil
end

local status = ERRORS_HTTP_CODES[err_t.code]
if not status or status == 500 then
return app_helpers.yield_error(err_t)
Expand Down
4 changes: 4 additions & 0 deletions kong/api/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ local function new_db_on_error(self)
return responses.send_HTTP_INTERNAL_SERVER_ERROR(tostring(err))
end

if err.strategy then
err.strategy = nil
end

if err.code == Errors.codes.SCHEMA_VIOLATION
or err.code == Errors.codes.INVALID_PRIMARY_KEY
or err.code == Errors.codes.FOREIGN_KEY_VIOLATION
Expand Down
5 changes: 4 additions & 1 deletion kong/db/dao/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ local log = ngx.log
local fmt = string.format



local ERR = ngx.ERR


Expand Down Expand Up @@ -297,6 +296,10 @@ function DAO:each(size)
local row, err, page = next_row()
if not row then
if err then
if type(err) == "table" then
return nil, tostring(err), err
end

local err_t = self.errors:database_error(err)
return nil, tostring(err_t), err_t
end
Expand Down
2 changes: 1 addition & 1 deletion kong/db/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function DB.new(kong_config, strategy)

-- load errors

local errors = Errors.new(strategy)
local errors = Errors.new(strategy or kong_config.database)

local schemas = {}

Expand Down