aboutsummaryrefslogtreecommitdiffstats
path: root/net/httpserver.lua
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2011-02-23 02:03:55 +0500
committerWaqas Hussain <waqas20@gmail.com>2011-02-23 02:03:55 +0500
commit51debb35354d6d01c2a4674946b1d477abea2d09 (patch)
tree3fbb2b4088ad066200f92cfcc5b00a78c2abbbf5 /net/httpserver.lua
parent9c85f1fccd8d28f20f3a1dbe341f505436fac7dd (diff)
downloadprosody-51debb35354d6d01c2a4674946b1d477abea2d09.tar.gz
prosody-51debb35354d6d01c2a4674946b1d477abea2d09.zip
net.httpserver: Catch errors thrown in HTTP handlers.
Diffstat (limited to 'net/httpserver.lua')
-rw-r--r--net/httpserver.lua8
1 files changed, 8 insertions, 0 deletions
diff --git a/net/httpserver.lua b/net/httpserver.lua
index 33ced072..6d6408f7 100644
--- a/net/httpserver.lua
+++ b/net/httpserver.lua
@@ -17,6 +17,8 @@ local listener;
local t_insert, t_concat = table.insert, table.concat;
local tonumber, tostring, pairs, ipairs, type = tonumber, tostring, pairs, ipairs, type;
+local xpcall = xpcall;
+local debug_traceback = debug.traceback;
local urlencode = function (s) return s and (s:gsub("%W", function (c) return ("%%%02x"):format(c:byte()); end)); end
@@ -86,6 +88,12 @@ local function call_callback(request, err)
callback = (request.server and request.server.handlers[base]) or default_handler;
end
if callback then
+ local _callback = callback;
+ function callback(a, b, c)
+ local status, result = xpcall(function() _callback(a, b, c) end, debug_traceback);
+ if status then return result; end
+ log("error", "Error in HTTP server handler: %s", result);
+ end
if err then
log("debug", "Request error: "..err);
if not callback(nil, err, request) then