From f818bd49f24afd9b590dd2e90989e0e1c659e1f5 Mon Sep 17 00:00:00 2001 From: thefosk Date: Thu, 5 Mar 2015 18:48:33 -0800 Subject: [PATCH] JSON errors for API --- src/kong/web/app.lua | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/kong/web/app.lua b/src/kong/web/app.lua index 97d03c68c65..a1e021ee51f 100644 --- a/src/kong/web/app.lua +++ b/src/kong/web/app.lua @@ -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) @@ -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()