comparison util/pubsub.lua @ 13535:88cab98aa28c

mod_pubsub: Move precondition error wrangling out of util.pubsub Removes dependency on util.error from util.pubsub which was only used for this one special case. Line count reduction! Would be even nicer if templating could be done by util.error itself.
author Kim Alvefur <zash@zash.se>
date Tue, 29 Oct 2024 14:56:02 +0100
parents fdd1438d9ef7
children 3b357ab6b6eb
comparison
equal deleted inserted replaced
13534:d532176d4334 13535:88cab98aa28c
1 local events = require "prosody.util.events"; 1 local events = require "prosody.util.events";
2 local cache = require "prosody.util.cache"; 2 local cache = require "prosody.util.cache";
3 local errors = require "prosody.util.error";
4 3
5 local service_mt = {}; 4 local service_mt = {};
6 5
7 local default_config = { 6 local default_config = {
8 max_items = 256; 7 max_items = 256;
560 node_obj = self.nodes[node]; 559 node_obj = self.nodes[node];
561 elseif requested_config and not requested_config._defaults_only then 560 elseif requested_config and not requested_config._defaults_only then
562 -- Check that node has the requested config before we publish 561 -- Check that node has the requested config before we publish
563 local ok, field = check_preconditions(node_obj.config, requested_config); 562 local ok, field = check_preconditions(node_obj.config, requested_config);
564 if not ok then 563 if not ok then
565 local err = errors.new({ 564 return false, "precondition-not-met", { field = field };
566 type = "cancel", condition = "conflict", text = "Field does not match: "..field;
567 });
568 err.pubsub_condition = "precondition-not-met";
569 return false, err;
570 end 565 end
571 end 566 end
572 if not self.config.itemcheck(item) then 567 if not self.config.itemcheck(item) then
573 return nil, "invalid-item"; 568 return nil, "invalid-item";
574 end 569 end