Make errors catchable and (de)register at config node of all nodes

This commit is contained in:
bvmensvoort
2023-06-11 10:50:15 +02:00
committed by Skylar Sadlier
parent f48ba74a72
commit 20c7182511
6 changed files with 51 additions and 20 deletions
+11 -5
View File
@@ -12,25 +12,27 @@ module.exports = function(RED) {
this.sharedSecret = this.credentials.sharedSecret;
if(!this.server) {
node.error('Server URL must be configured on the node.');
node.error('Server URL must be configured on the node.', {});
return;
}
if(!this.sharedSecret) {
node.error('Shared registration secret must be configured on the node.');
node.error('Shared registration secret must be configured on the node.', {});
return;
}
node.server.register(node);
node.on("input", async function (msg) {
const { got } = await import('got');
if(!msg.payload.username) {
node.error("msg.payload.username is required");
node.error("msg.payload.username is required", {});
return;
}
if(!msg.payload.password) {
node.error("msg.payload.password is required");
node.error("msg.payload.password is required", {});
return;
}
@@ -50,7 +52,7 @@ module.exports = function(RED) {
var nonce = response.body.nonce;
if(!nonce) {
node.error('Could not get nonce from /_synapse/admin/v1/register');
node.error('Could not get nonce from /_synapse/admin/v1/register', {});
return;
}
@@ -96,6 +98,10 @@ module.exports = function(RED) {
node.send(msg);
})();
});
node.on("close", function() {
node.server.deregister(node);
});
}
RED.nodes.registerType("matrix-synapse-register", MatrixSynapseRegister, {
credentials: {