Skip to content

Commit

Permalink
Fixed a failed error parsing on Postgres.
Browse files Browse the repository at this point in the history
Prevent it from exploding into a Lua error, obfuscating the real error. Now returns the DB error.
See issue Kong#1239
  • Loading branch information
Tieske committed May 30, 2016
1 parent f69843d commit c069ff4
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions kong/dao/postgres_db.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,17 @@ local function parse_error(err_str)
local err
if string.find(err_str, "Key .* already exists") then
local col, value = string.match(err_str, "%((.+)%)=%((.+)%)")
err = Errors.unique {[col] = value}
if col then
err = Errors.unique {[col] = value}
end
elseif string.find(err_str, "violates foreign key constraint") then
local col, value = string.match(err_str, "%((.+)%)=%((.+)%)")
err = Errors.foreign {[col] = value}
else
err = Errors.db(err_str)
if col then
err = Errors.foreign {[col] = value}
end
end

return err
return err or Errors.db(err_str)
end

local function get_select_fields(schema)
Expand Down

0 comments on commit c069ff4

Please sign in to comment.