Skip to content

Commit

Permalink
JSON errors for API
Browse files Browse the repository at this point in the history
  • Loading branch information
subnetmarco committed Mar 6, 2015
1 parent e4472f2 commit f818bd4
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/kong/web/app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ local Applications = require "kong.web.routes.applications"
app = lapis.Application()

app:get("/", function(self)

local db_plugins, err = dao.plugins:find_distinct()
if err then
ngx.log(ngx.ERR, err)
Expand All @@ -31,6 +30,26 @@ app.handle_404 = function(self)
return utils.not_found()
end

app.handle_error = function(self, err, trace)
ngx.log(ngx.ERR, err.."\n"..trace)

local iterator, iter_err = ngx.re.gmatch(err, ".+:\\d+:\\s*(.+)")
if iter_err then
ngx.log(ngx.ERR, err)
end

local m, err = iterator()
if err then
ngx.log(ngx.ERR, err)
end

if m and table.getn(m) > 0 then
utils.show_error(500, m[1])
else
ngx.log(ngx.ERR, "Can't parse error")
end
end

-- Load controllers
Apis()
Accounts()
Expand Down

0 comments on commit f818bd4

Please sign in to comment.