mirror of
https://github.com/Skylar-Tech/node-red-contrib-matrix-chat.git
synced 2025-04-19 20:43:04 -06:00
Make errors of nodes catchable by a catch node
This commit is contained in:
parent
8a7fba39e8
commit
8ca11f36d8
@ -8,7 +8,7 @@ module.exports = function(RED) {
|
|||||||
this.server = RED.nodes.getNode(n.server);
|
this.server = RED.nodes.getNode(n.server);
|
||||||
|
|
||||||
if(!this.server) {
|
if(!this.server) {
|
||||||
node.error('Server must be configured on the node.');
|
node.error('Server must be configured on the node.', {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!node.server.isConnected()) {
|
if(!node.server.isConnected()) {
|
||||||
node.error("Matrix server connection is currently closed");
|
node.error("Matrix server connection is currently closed", {});
|
||||||
node.send([null, msg]);
|
node.send([null, msg]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ module.exports = function(RED) {
|
|||||||
node.on('input', function(msg) {
|
node.on('input', function(msg) {
|
||||||
|
|
||||||
if(!msg.eventId) {
|
if(!msg.eventId) {
|
||||||
node.error("eventId is missing");
|
node.error("eventId is missing", {});
|
||||||
node.send([null, msg])
|
node.send([null, msg])
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -38,7 +38,7 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!node.server.isConnected()) {
|
if(!node.server.isConnected()) {
|
||||||
node.error("Matrix server connection is currently closed");
|
node.error("Matrix server connection is currently closed", {});
|
||||||
node.send([null, msg]);
|
node.send([null, msg]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ module.exports = function(RED) {
|
|||||||
this.roomId = n.roomId;
|
this.roomId = n.roomId;
|
||||||
|
|
||||||
if(!this.server) {
|
if(!this.server) {
|
||||||
node.error('Server must be configured on the node.');
|
node.error('Server must be configured on the node.', {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,18 +37,18 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
node.on("input", function (msg) {
|
node.on("input", function (msg) {
|
||||||
if (! node.server || ! node.server.matrixClient) {
|
if (! node.server || ! node.server.matrixClient) {
|
||||||
node.error("No matrix server selected");
|
node.error("No matrix server selected", {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!node.server.isConnected()) {
|
if(!node.server.isConnected()) {
|
||||||
node.error("Matrix server connection is currently closed");
|
node.error("Matrix server connection is currently closed", {});
|
||||||
node.send([null, msg]);
|
node.send([null, msg]);
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.topic = node.roomId || msg.topic;
|
msg.topic = node.roomId || msg.topic;
|
||||||
if(!msg.topic) {
|
if(!msg.topic) {
|
||||||
node.error("room must be defined in either msg.topic or in node config");
|
node.error("room must be defined in either msg.topic or in node config", {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,17 +24,17 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
node.on("input", function (msg) {
|
node.on("input", function (msg) {
|
||||||
if (! node.server || ! node.server.matrixClient) {
|
if (! node.server || ! node.server.matrixClient) {
|
||||||
node.error("No matrix server selected");
|
node.error("No matrix server selected", {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!node.server.isConnected()) {
|
if(!node.server.isConnected()) {
|
||||||
node.error("Matrix server connection is currently closed");
|
node.error("Matrix server connection is currently closed", {});
|
||||||
node.send([null, msg]);
|
node.send([null, msg]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!msg.topic) {
|
if(!msg.topic) {
|
||||||
node.error("Room must be specified in msg.topic");
|
node.error("Room must be specified in msg.topic", {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ module.exports = function(RED) {
|
|||||||
node.send([msg, null]);
|
node.send([msg, null]);
|
||||||
})
|
})
|
||||||
.catch(function(e){
|
.catch(function(e){
|
||||||
node.error("Error trying to join room " + msg.topic + ":" + e);
|
node.error("Error trying to join room " + msg.topic + ":" + e, {});
|
||||||
msg.error = e;
|
msg.error = e;
|
||||||
node.send([null, msg]);
|
node.send([null, msg]);
|
||||||
});
|
});
|
||||||
|
@ -11,7 +11,7 @@ module.exports = function(RED) {
|
|||||||
node.status({ fill: "red", shape: "ring", text: "disconnected" });
|
node.status({ fill: "red", shape: "ring", text: "disconnected" });
|
||||||
|
|
||||||
if (!node.server) {
|
if (!node.server) {
|
||||||
node.error("No configuration node");
|
node.error("No configuration node", {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,17 +25,17 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
node.on('input', function(msg) {
|
node.on('input', function(msg) {
|
||||||
if (! node.server || ! node.server.matrixClient) {
|
if (! node.server || ! node.server.matrixClient) {
|
||||||
node.error("No matrix server selected");
|
node.error("No matrix server selected", {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!msg.topic) {
|
if(!msg.topic) {
|
||||||
node.error('No room provided in msg.topic');
|
node.error('No room provided in msg.topic', {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!node.server.isConnected()) {
|
if(!node.server.isConnected()) {
|
||||||
node.error("Matrix server connection is currently closed");
|
node.error("Matrix server connection is currently closed", {});
|
||||||
node.send([null, msg]);
|
node.send([null, msg]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ module.exports = function(RED) {
|
|||||||
node.server.matrixClient.leave(msg.topic);
|
node.server.matrixClient.leave(msg.topic);
|
||||||
node.send([msg, null]);
|
node.send([msg, null]);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
node.error("Failed to leave room " + msg.topic + ": " + e);
|
node.error("Failed to leave room " + msg.topic + ": " + e, {});
|
||||||
msg.payload = e;
|
msg.payload = e;
|
||||||
node.send([null, msg]);
|
node.send([null, msg]);
|
||||||
}
|
}
|
||||||
|
@ -26,30 +26,30 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
node.on("input", function (msg) {
|
node.on("input", function (msg) {
|
||||||
if (!node.server || !node.server.matrixClient) {
|
if (!node.server || !node.server.matrixClient) {
|
||||||
node.error("No matrix server selected");
|
node.error("No matrix server selected", {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!node.server.isConnected()) {
|
if(!node.server.isConnected()) {
|
||||||
node.error("Matrix server connection is currently closed");
|
node.error("Matrix server connection is currently closed", {});
|
||||||
node.send([null, msg]);
|
node.send([null, msg]);
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.topic = node.roomId || msg.topic;
|
msg.topic = node.roomId || msg.topic;
|
||||||
if(!msg.topic) {
|
if(!msg.topic) {
|
||||||
node.error("Room must be specified in msg.topic or in configuration");
|
node.error("Room must be specified in msg.topic or in configuration", {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let payload = n.reaction || msg.payload;
|
let payload = n.reaction || msg.payload;
|
||||||
if(!payload) {
|
if(!payload) {
|
||||||
node.error('msg.payload must be defined or the reaction configured on the node.');
|
node.error('msg.payload must be defined or the reaction configured on the node.', {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let eventId = msg.referenceEventId || msg.eventId;
|
let eventId = msg.referenceEventId || msg.eventId;
|
||||||
if(!eventId) {
|
if(!eventId) {
|
||||||
node.error('Either msg.referenceEventId or msg.eventId must be defined to react to a message.');
|
node.error('Either msg.referenceEventId or msg.eventId must be defined to react to a message.', {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ module.exports = function(RED) {
|
|||||||
node.status({ fill: "red", shape: "ring", text: "disconnected" });
|
node.status({ fill: "red", shape: "ring", text: "disconnected" });
|
||||||
|
|
||||||
if (!node.server) {
|
if (!node.server) {
|
||||||
node.error("No configuration node");
|
node.error("No configuration node", {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,23 +26,23 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
node.on("input", function (msg) {
|
node.on("input", function (msg) {
|
||||||
if (! node.server || ! node.server.matrixClient) {
|
if (! node.server || ! node.server.matrixClient) {
|
||||||
node.error("No matrix server selected");
|
node.error("No matrix server selected", {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!node.server.isConnected()) {
|
if(!node.server.isConnected()) {
|
||||||
node.error("Matrix server connection is currently closed");
|
node.error("Matrix server connection is currently closed", {});
|
||||||
node.send([null, msg]);
|
node.send([null, msg]);
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.topic = node.roomId || msg.topic;
|
msg.topic = node.roomId || msg.topic;
|
||||||
if(!msg.topic) {
|
if(!msg.topic) {
|
||||||
node.error("Room must be specified in msg.topic or in configuration");
|
node.error("Room must be specified in msg.topic or in configuration", {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!msg.userId) {
|
if(!msg.userId) {
|
||||||
node.error("msg.userId was not set.");
|
node.error("msg.userId was not set.", {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ module.exports = function(RED) {
|
|||||||
node.send([msg, null]);
|
node.send([msg, null]);
|
||||||
})
|
})
|
||||||
.catch(function(e){
|
.catch(function(e){
|
||||||
node.error("Error trying to ban " + msg.userId + " from " + msg.topic);
|
node.error("Error trying to ban " + msg.userId + " from " + msg.topic, {});
|
||||||
msg.error = e;
|
msg.error = e;
|
||||||
node.send([null, msg]);
|
node.send([null, msg]);
|
||||||
});
|
});
|
||||||
|
@ -9,7 +9,7 @@ module.exports = function(RED) {
|
|||||||
this.roomId = n.roomId;
|
this.roomId = n.roomId;
|
||||||
|
|
||||||
if(!this.server) {
|
if(!this.server) {
|
||||||
node.error('Server must be configured on the node.');
|
node.error('Server must be configured on the node.', {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,23 +26,23 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
node.on("input", function (msg) {
|
node.on("input", function (msg) {
|
||||||
if (! node.server || ! node.server.matrixClient) {
|
if (! node.server || ! node.server.matrixClient) {
|
||||||
node.error("No matrix server selected");
|
node.error("No matrix server selected", {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!node.server.isConnected()) {
|
if(!node.server.isConnected()) {
|
||||||
node.error("Matrix server connection is currently closed");
|
node.error("Matrix server connection is currently closed", {});
|
||||||
node.send([null, msg]);
|
node.send([null, msg]);
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.topic = node.roomId || msg.topic;
|
msg.topic = node.roomId || msg.topic;
|
||||||
if(!msg.topic) {
|
if(!msg.topic) {
|
||||||
node.error("Room must be specified in msg.topic or in configuration");
|
node.error("Room must be specified in msg.topic or in configuration", {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!msg.userId) {
|
if(!msg.userId) {
|
||||||
node.error("msg.userId was not set.");
|
node.error("msg.userId was not set.", {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ module.exports = function(RED) {
|
|||||||
node.send([msg, null]);
|
node.send([msg, null]);
|
||||||
})
|
})
|
||||||
.catch(function(e){
|
.catch(function(e){
|
||||||
node.error("Error trying to kick " + msg.userId + " from " + msg.topic);
|
node.error("Error trying to kick " + msg.userId + " from " + msg.topic, {});
|
||||||
msg.error = e;
|
msg.error = e;
|
||||||
node.send([null, msg]);
|
node.send([null, msg]);
|
||||||
});
|
});
|
||||||
|
@ -31,13 +31,13 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!node.server.isConnected()) {
|
if(!node.server.isConnected()) {
|
||||||
node.error("Matrix server connection is currently closed");
|
node.error("Matrix server connection is currently closed", {});
|
||||||
node.send([null, msg]);
|
node.send([null, msg]);
|
||||||
}
|
}
|
||||||
|
|
||||||
let roomId = node.roomId || msg.topic;
|
let roomId = node.roomId || msg.topic;
|
||||||
if(!roomId) {
|
if(!roomId) {
|
||||||
node.error("msg.topic is required. Specify in the input or configure the room ID on the node.");
|
node.error("msg.topic is required. Specify in the input or configure the room ID on the node.", {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!node.server.isConnected()) {
|
if(!node.server.isConnected()) {
|
||||||
node.error("Matrix server connection is currently closed");
|
node.error("Matrix server connection is currently closed", {});
|
||||||
node.send([null, msg]);
|
node.send([null, msg]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!msg.payload) {
|
if(!msg.payload) {
|
||||||
node.error('msg.payload is required');
|
node.error('msg.payload is required', {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!node.server.isConnected()) {
|
if(!node.server.isConnected()) {
|
||||||
node.error("Matrix server connection is currently closed");
|
node.error("Matrix server connection is currently closed", {});
|
||||||
node.send([null, msg]);
|
node.send([null, msg]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!msg.payload) {
|
if(!msg.payload) {
|
||||||
node.error('msg.payload is required');
|
node.error('msg.payload is required', {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
if(msgType === 'msg.type') {
|
if(msgType === 'msg.type') {
|
||||||
if(!msg.type) {
|
if(!msg.type) {
|
||||||
node.error("msg.type type is set to be passed in via msg.type but was not defined");
|
node.error("msg.type type is set to be passed in via msg.type but was not defined", {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
msgType = msg.type;
|
msgType = msg.type;
|
||||||
@ -79,7 +79,7 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
if(msgFormat === 'msg.format') {
|
if(msgFormat === 'msg.format') {
|
||||||
if(!msg.format) {
|
if(!msg.format) {
|
||||||
node.error("Message format is set to be passed in via msg.format but was not defined");
|
node.error("Message format is set to be passed in via msg.format but was not defined", {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
msgFormat = msg.format;
|
msgFormat = msg.format;
|
||||||
@ -91,7 +91,7 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!node.server.isConnected()) {
|
if(!node.server.isConnected()) {
|
||||||
node.error("Matrix server connection is currently closed");
|
node.error("Matrix server connection is currently closed", {});
|
||||||
node.send([null, msg]);
|
node.send([null, msg]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -104,7 +104,7 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
let payload = n.message || msg.payload;
|
let payload = n.message || msg.payload;
|
||||||
if(!payload) {
|
if(!payload) {
|
||||||
node.error('msg.payload must be defined or the message configured on the node.');
|
node.error('msg.payload must be defined or the message configured on the node.', {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user