Comparison

core/moduleapi.lua @ 10576:f88f1151bc72

core.moduleapi: Rename local name for util.error for consistency It's called 'errors' everywhere else except here.
author Kim Alvefur <zash@zash.se>
date Mon, 30 Dec 2019 09:54:49 +0100
parent 10575:5cf8e96575b3
child 10595:17bab303daf5
comparison
equal deleted inserted replaced
10575:5cf8e96575b3 10576:f88f1151bc72
13 local pluginloader = require "util.pluginloader"; 13 local pluginloader = require "util.pluginloader";
14 local timer = require "util.timer"; 14 local timer = require "util.timer";
15 local resolve_relative_path = require"util.paths".resolve_relative_path; 15 local resolve_relative_path = require"util.paths".resolve_relative_path;
16 local st = require "util.stanza"; 16 local st = require "util.stanza";
17 local cache = require "util.cache"; 17 local cache = require "util.cache";
18 local errutil = require "util.error"; 18 local errors = require "util.error";
19 local promise = require "util.promise"; 19 local promise = require "util.promise";
20 local time_now = require "util.time".now; 20 local time_now = require "util.time".now;
21 local format = require "util.format".format; 21 local format = require "util.format".format;
22 22
23 local t_insert, t_remove, t_concat = table.insert, table.remove, table.concat; 23 local t_insert, t_remove, t_concat = table.insert, table.remove, table.concat;
368 368
369 function api:send_iq(stanza, origin, timeout) 369 function api:send_iq(stanza, origin, timeout)
370 local iq_cache = self._iq_cache; 370 local iq_cache = self._iq_cache;
371 if not iq_cache then 371 if not iq_cache then
372 iq_cache = cache.new(256, function (_, iq) 372 iq_cache = cache.new(256, function (_, iq)
373 iq.reject(errutil.new({ 373 iq.reject(errors.new({
374 type = "wait", condition = "resource-constraint", 374 type = "wait", condition = "resource-constraint",
375 text = "evicted from iq tracking cache" 375 text = "evicted from iq tracking cache"
376 })); 376 }));
377 end); 377 end);
378 self._iq_cache = iq_cache; 378 self._iq_cache = iq_cache;
396 end 396 end
397 end 397 end
398 398
399 local function error_handler(event) 399 local function error_handler(event)
400 if event.stanza.attr.from == stanza.attr.to then 400 if event.stanza.attr.from == stanza.attr.to then
401 reject(errutil.from_stanza(event.stanza, event)); 401 reject(errors.from_stanza(event.stanza, event));
402 return true; 402 return true;
403 end 403 end
404 end 404 end
405 405
406 if iq_cache:get(cache_key) then 406 if iq_cache:get(cache_key) then
407 reject(errutil.new({ 407 reject(errors.new({
408 type = "modify", condition = "conflict", 408 type = "modify", condition = "conflict",
409 text = "IQ stanza id attribute already used", 409 text = "IQ stanza id attribute already used",
410 })); 410 }));
411 return; 411 return;
412 end 412 end
413 413
414 self:hook(result_event, result_handler); 414 self:hook(result_event, result_handler);
415 self:hook(error_event, error_handler); 415 self:hook(error_event, error_handler);
416 416
417 local timeout_handle = self:add_timer(timeout or 120, function () 417 local timeout_handle = self:add_timer(timeout or 120, function ()
418 reject(errutil.new({ 418 reject(errors.new({
419 type = "wait", condition = "remote-server-timeout", 419 type = "wait", condition = "remote-server-timeout",
420 text = "IQ stanza timed out", 420 text = "IQ stanza timed out",
421 })); 421 }));
422 end); 422 end);
423 423
426 timeout_handle = timeout_handle, 426 timeout_handle = timeout_handle,
427 result_handler = result_handler, error_handler = error_handler; 427 result_handler = result_handler, error_handler = error_handler;
428 }); 428 });
429 429
430 if not ok then 430 if not ok then
431 reject(errutil.new({ 431 reject(errors.new({
432 type = "wait", condition = "internal-server-error", 432 type = "wait", condition = "internal-server-error",
433 text = "Could not store IQ tracking data" 433 text = "Could not store IQ tracking data"
434 })); 434 }));
435 return; 435 return;
436 end 436 end