# HG changeset patch # User Matthew Wild # Date 1759177698 -3600 # Node ID 4f6fb56572f7eca2998c935a72eb22134fdaa89f # Parent 2623515d850713ffe70d6fe25c53e10149a7286d mod_protect_last_admin: Return util.error object to provide more information diff -r 2623515d8507 -r 4f6fb56572f7 mod_protect_last_admin/mod_protect_last_admin.lua --- a/mod_protect_last_admin/mod_protect_last_admin.lua Thu Sep 25 18:21:27 2025 +0100 +++ b/mod_protect_last_admin/mod_protect_last_admin.lua Mon Sep 29 21:28:18 2025 +0100 @@ -6,6 +6,19 @@ local protected_roles = module:get_option_set("protect_last_admin_roles", { "prosody:admin", "prosody:operator" }); +local errors = require "prosody.util.error".init(module.name, { + ["cannot-remove-only-admin"] = { + code = 400; + type = "cancel"; + condition = "policy-violation"; + text = "Cannot remove the only administrator"; + extra = { + namespace = "https://prosody.im/protocol/errors"; + condition = "cannot-remove-only-admin"; + }; + }; +}); + local function other_protected_users(username, host) local protected_users = set.new(); for protected_role in protected_roles do @@ -39,7 +52,7 @@ end if not other_protected_users(username, host) then - event.reason = "Cannot remove the only administrator"; + event.reason = errors.new("cannot-remove-only-admin"); return false; end module:log("debug", "Permitting event, no reason not to!");