Skip to content
Open
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
34 changes: 18 additions & 16 deletions lua/express/router/layer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,28 @@ LAYER_MT.__index = LAYER_MT

-- Handle the error for the layer.
function LAYER_MT:handle_error(err, req, res, next)
local fn = self.handle
if debug.getinfo(fn, "Su").nparams ~= 4 then
-- not a standard error handler
return next(err)
end

local ok, er = pcall(fn, err, req, res, next)
if not ok then next(er) end
local fn = self.handle
local info = debug.getinfo(fn, "Su")
if not info or not info.nparams or info.nparams ~= 4 then
-- not a standard error handler
return next(err)
end

local ok, er = pcall(fn, err, req, res, next)
if not ok then next(er) end
end

-- Handle the request for the layer.
function LAYER_MT:handle_request(req, res, next)
local fn = self.handle
if debug.getinfo(fn, "Su").nparams > 3 then
-- not a standard error handler
return next()
end

local ok, err = pcall(fn, req, res, next)
if not ok then next(err) end -- если ошибка в app:get() хендлере, то не останавливаемся, а идем к следующему, передавая ошибку дальше
local fn = self.handle
local info = debug.getinfo(fn, "Su")
if info and info.nparams and info.nparams > 3 then
-- not a standard request handler
return next()
end

local ok, err = pcall(fn, req, res, next)
if not ok then next(err) end
end

-- Check if this route matches `path`, if so populate `.params`.
Expand Down