Comparison

net/http/server.lua @ 10394:955e54e451dc

net.http.server: Handle util.error objects from http handlers
author Kim Alvefur <zash@zash.se>
date Fri, 01 Nov 2019 22:30:35 +0100
parent 10393:0ea7b4769096
child 10395:faa4fcc78b14
comparison
equal deleted inserted replaced
10393:0ea7b4769096 10394:955e54e451dc
11 local xpcall = require "util.xpcall".xpcall; 11 local xpcall = require "util.xpcall".xpcall;
12 local traceback = debug.traceback; 12 local traceback = debug.traceback;
13 local tostring = tostring; 13 local tostring = tostring;
14 local cache = require "util.cache"; 14 local cache = require "util.cache";
15 local codes = require "net.http.codes"; 15 local codes = require "net.http.codes";
16 local errors = require "util.error";
16 local blocksize = 2^16; 17 local blocksize = 2^16;
17 18
18 local _M = {}; 19 local _M = {};
19 20
20 local sessions = {}; 21 local sessions = {};
186 if result >= 400 then 187 if result >= 400 then
187 body = events.fire_event("http-error", { request = request, response = response, code = result }); 188 body = events.fire_event("http-error", { request = request, response = response, code = result });
188 end 189 end
189 elseif result_type == "string" then 190 elseif result_type == "string" then
190 body = result; 191 body = result;
192 elseif errors.is_err(result) then
193 body = events.fire_event("http-error", { request = request, response = response, code = result.code, error = result });
191 elseif result_type == "table" then 194 elseif result_type == "table" then
192 for k, v in pairs(result) do 195 for k, v in pairs(result) do
193 if k ~= "headers" then 196 if k ~= "headers" then
194 response[k] = v; 197 response[k] = v;
195 else 198 else