comparison mod_http_muc_log/mod_http_muc_log.lua @ 3066:cefc375d0929

mod_http_muc_log: Handle errors while loading template file in a more graceful manner
author Kim Alvefur <zash@zash.se>
date Tue, 29 May 2018 05:50:19 +0200
parents ce61f1826f1f
children 97b8b07ae1d1
comparison
equal deleted inserted replaced
3065:49254b9cc751 3066:cefc375d0929
30 module:depends"http"; 30 module:depends"http";
31 31
32 local template; 32 local template;
33 do 33 do
34 local template_filename = module:get_option_string(module.name .. "_template", module.name .. ".html"); 34 local template_filename = module:get_option_string(module.name .. "_template", module.name .. ".html");
35 local template_file = assert(module:load_resource(template_filename)); 35 local template_file, err = module:load_resource(template_filename);
36 template = template_file:read("*a"); 36 if template_file then
37 template_file:close(); 37 template, err = template_file:read("*a");
38 template_file:close();
39 end
40 if not template then
41 module:log("error", "Error loading template: %s", err);
42 template = render("<h1>mod_{module} could not read the template</h1><p>Tried to open <b>{filename}</b><pre>{error}</pre>",
43 { module = module.name, filename = template_filename, error = err });
44 end
38 end 45 end
39 46
40 -- local base_url = module:http_url() .. '/'; -- TODO: Generate links in a smart way 47 -- local base_url = module:http_url() .. '/'; -- TODO: Generate links in a smart way
41 local get_link do 48 local get_link do
42 local link, path = { path = '/' }, { "", "", is_directory = true }; 49 local link, path = { path = '/' }, { "", "", is_directory = true };