comparison mod_rest/mod_rest.lua @ 3873:fea0c1bed1a0

mod_rest: Back out 513a8a7fab41 I see the mistake now > if true or ...
author Kim Alvefur <zash@zash.se>
date Tue, 04 Feb 2020 20:19:09 +0100
parents 513a8a7fab41
children 505ae524b635
comparison
equal deleted inserted replaced
3872:513a8a7fab41 3873:fea0c1bed1a0
313 module:hook("message/host", handle_stanza, -1); 313 module:hook("message/host", handle_stanza, -1);
314 module:hook("presence/host", handle_stanza, -1); 314 module:hook("presence/host", handle_stanza, -1);
315 end 315 end
316 end 316 end
317 317
318 if module:get_option_boolean("rest_json_errors", false) then 318 local http_server = require "net.http.server";
319 local http_server = require "net.http.server"; 319 module:hook_object_event(http_server, "http-error", function (event)
320 module:hook_object_event(http_server, "http-error", function (event) 320 local request, response = event.request, event.response;
321 local request, response = event.request, event.response; 321 if true or decide_type(request and request.headers.accept or "") == "application/json" then
322 if true or decide_type(request and request.headers.accept or "") == "application/json" then 322 if response then
323 if response then 323 response.headers.content_type = "application/json";
324 response.headers.content_type = "application/json"; 324 end
325 end 325 return json.encode({
326 return json.encode({ 326 type = "error",
327 type = "error", 327 error = event.error,
328 error = event.error, 328 code = event.code,
329 code = event.code, 329 });
330 }); 330 end
331 end 331 end, 10);
332 end, 10);
333 end