mirror of
https://github.com/Skylar-Tech/node-red-contrib-matrix-chat.git
synced 2025-04-19 12:33:06 -06:00
Pass msg object where possible
As described on https://nodered.org/docs/user-guide/writing-functions#handling-errors
This commit is contained in:
parent
2bd0fa48e2
commit
bfb840d3a7
@ -42,7 +42,7 @@ module.exports = function(RED) {
|
||||
}
|
||||
|
||||
if(!node.server.isConnected()) {
|
||||
node.error("Matrix server connection is currently closed", {});
|
||||
node.error("Matrix server connection is currently closed", msg);
|
||||
node.send([null, msg]);
|
||||
}
|
||||
|
||||
|
@ -12,22 +12,22 @@ module.exports = function(RED) {
|
||||
const { got } = await import('got');
|
||||
|
||||
if(!msg.type) {
|
||||
node.error('msg.type is required.');
|
||||
node.error('msg.type is required.', msg);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!msg.content) {
|
||||
node.error('msg.content is required.');
|
||||
node.error('msg.content is required.', msg);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!msg.content.file) {
|
||||
node.error('msg.content.file is required.');
|
||||
node.error('msg.content.file is required.', msg);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!msg.url) {
|
||||
node.error('msg.url is required.');
|
||||
node.error('msg.url is required.', msg);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ module.exports = function(RED) {
|
||||
node.on('input', function(msg) {
|
||||
|
||||
if(!msg.eventId) {
|
||||
node.error("eventId is missing", {});
|
||||
node.error("eventId is missing", msg);
|
||||
node.send([null, msg])
|
||||
return;
|
||||
}
|
||||
@ -39,7 +39,7 @@ module.exports = function(RED) {
|
||||
}
|
||||
|
||||
if(!node.server.isConnected()) {
|
||||
node.error("Matrix server connection is currently closed", {});
|
||||
node.error("Matrix server connection is currently closed", msg);
|
||||
node.send([null, msg]);
|
||||
return;
|
||||
}
|
||||
|
@ -38,18 +38,18 @@ module.exports = function(RED) {
|
||||
|
||||
node.on("input", function (msg) {
|
||||
if (! node.server || ! node.server.matrixClient) {
|
||||
node.error("No matrix server selected", {});
|
||||
node.error("No matrix server selected", msg);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!node.server.isConnected()) {
|
||||
node.error("Matrix server connection is currently closed", {});
|
||||
node.error("Matrix server connection is currently closed", msg);
|
||||
node.send([null, msg]);
|
||||
}
|
||||
|
||||
msg.topic = node.roomId || 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", msg);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -25,17 +25,17 @@ module.exports = function(RED) {
|
||||
|
||||
node.on("input", function (msg) {
|
||||
if (! node.server || ! node.server.matrixClient) {
|
||||
node.error("No matrix server selected", {});
|
||||
node.error("No matrix server selected", msg);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!node.server.isConnected()) {
|
||||
node.error("Matrix server connection is currently closed", {});
|
||||
node.error("Matrix server connection is currently closed", msg);
|
||||
node.send([null, msg]);
|
||||
}
|
||||
|
||||
if(!msg.topic) {
|
||||
node.error("Room must be specified in msg.topic", {});
|
||||
node.error("Room must be specified in msg.topic", msg);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ module.exports = function(RED) {
|
||||
node.send([msg, null]);
|
||||
})
|
||||
.catch(function(e){
|
||||
node.error("Error trying to join room " + msg.topic + ":" + e, {});
|
||||
node.error("Error trying to join room " + msg.topic + ":" + e, msg);
|
||||
msg.error = e;
|
||||
node.send([null, msg]);
|
||||
});
|
||||
|
@ -26,17 +26,17 @@ module.exports = function(RED) {
|
||||
|
||||
node.on('input', function(msg) {
|
||||
if (! node.server || ! node.server.matrixClient) {
|
||||
node.error("No matrix server selected", {});
|
||||
node.error("No matrix server selected", msg);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!msg.topic) {
|
||||
node.error('No room provided in msg.topic', {});
|
||||
node.error('No room provided in msg.topic', msg);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!node.server.isConnected()) {
|
||||
node.error("Matrix server connection is currently closed", {});
|
||||
node.error("Matrix server connection is currently closed", msg);
|
||||
node.send([null, msg]);
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ module.exports = function(RED) {
|
||||
node.server.matrixClient.leave(msg.topic);
|
||||
node.send([msg, null]);
|
||||
} catch(e) {
|
||||
node.error("Failed to leave room " + msg.topic + ": " + e, {});
|
||||
node.error("Failed to leave room " + msg.topic + ": " + e, msg);
|
||||
msg.payload = e;
|
||||
node.send([null, msg]);
|
||||
}
|
||||
|
@ -27,30 +27,30 @@ module.exports = function(RED) {
|
||||
|
||||
node.on("input", function (msg) {
|
||||
if (!node.server || !node.server.matrixClient) {
|
||||
node.error("No matrix server selected", {});
|
||||
node.error("No matrix server selected", msg);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!node.server.isConnected()) {
|
||||
node.error("Matrix server connection is currently closed", {});
|
||||
node.error("Matrix server connection is currently closed", msg);
|
||||
node.send([null, msg]);
|
||||
}
|
||||
|
||||
msg.topic = node.roomId || 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", msg);
|
||||
return;
|
||||
}
|
||||
|
||||
let payload = n.reaction || msg.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.', msg);
|
||||
return;
|
||||
}
|
||||
|
||||
let eventId = msg.referenceEventId || msg.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.', msg);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -27,23 +27,23 @@ module.exports = function(RED) {
|
||||
|
||||
node.on("input", function (msg) {
|
||||
if (! node.server || ! node.server.matrixClient) {
|
||||
node.error("No matrix server selected", {});
|
||||
node.error("No matrix server selected", msg);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!node.server.isConnected()) {
|
||||
node.error("Matrix server connection is currently closed", {});
|
||||
node.error("Matrix server connection is currently closed", msg);
|
||||
node.send([null, msg]);
|
||||
}
|
||||
|
||||
msg.topic = node.roomId || 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", msg);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!msg.userId) {
|
||||
node.error("msg.userId was not set.", {});
|
||||
node.error("msg.userId was not set.", msg);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ module.exports = function(RED) {
|
||||
node.send([msg, null]);
|
||||
})
|
||||
.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);
|
||||
msg.error = e;
|
||||
node.send([null, msg]);
|
||||
});
|
||||
|
@ -27,23 +27,23 @@ module.exports = function(RED) {
|
||||
|
||||
node.on("input", function (msg) {
|
||||
if (! node.server || ! node.server.matrixClient) {
|
||||
node.error("No matrix server selected", {});
|
||||
node.error("No matrix server selected", msg);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!node.server.isConnected()) {
|
||||
node.error("Matrix server connection is currently closed", {});
|
||||
node.error("Matrix server connection is currently closed", msg);
|
||||
node.send([null, msg]);
|
||||
}
|
||||
|
||||
msg.topic = node.roomId || 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", msg);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!msg.userId) {
|
||||
node.error("msg.userId was not set.", {});
|
||||
node.error("msg.userId was not set.", msg);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ module.exports = function(RED) {
|
||||
node.send([msg, null]);
|
||||
})
|
||||
.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);
|
||||
msg.error = e;
|
||||
node.send([null, msg]);
|
||||
});
|
||||
|
@ -32,13 +32,13 @@ module.exports = function(RED) {
|
||||
}
|
||||
|
||||
if(!node.server.isConnected()) {
|
||||
node.error("Matrix server connection is currently closed", {});
|
||||
node.error("Matrix server connection is currently closed", msg);
|
||||
node.send([null, msg]);
|
||||
}
|
||||
|
||||
let roomId = node.roomId || msg.topic;
|
||||
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.", msg);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ module.exports = function(RED) {
|
||||
}
|
||||
|
||||
if(!node.server.isConnected()) {
|
||||
node.error("Matrix server connection is currently closed", {});
|
||||
node.error("Matrix server connection is currently closed", msg);
|
||||
node.send([null, msg]);
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ module.exports = function(RED) {
|
||||
}
|
||||
|
||||
if(!msg.payload) {
|
||||
node.error('msg.payload is required', {});
|
||||
node.error('msg.payload is required', msg);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ module.exports = function(RED) {
|
||||
}
|
||||
|
||||
if(!node.server.isConnected()) {
|
||||
node.error("Matrix server connection is currently closed", {});
|
||||
node.error("Matrix server connection is currently closed", msg);
|
||||
node.send([null, msg]);
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ module.exports = function(RED) {
|
||||
}
|
||||
|
||||
if(!msg.payload) {
|
||||
node.error('msg.payload is required', {});
|
||||
node.error('msg.payload is required', msg);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ module.exports = function(RED) {
|
||||
|
||||
if(msgType === '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", msg);
|
||||
return;
|
||||
}
|
||||
msgType = msg.type;
|
||||
@ -80,7 +80,7 @@ module.exports = function(RED) {
|
||||
|
||||
if(msgFormat === '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", msg);
|
||||
return;
|
||||
}
|
||||
msgFormat = msg.format;
|
||||
@ -92,7 +92,7 @@ module.exports = function(RED) {
|
||||
}
|
||||
|
||||
if(!node.server.isConnected()) {
|
||||
node.error("Matrix server connection is currently closed", {});
|
||||
node.error("Matrix server connection is currently closed", msg);
|
||||
node.send([null, msg]);
|
||||
return;
|
||||
}
|
||||
@ -105,7 +105,7 @@ module.exports = function(RED) {
|
||||
|
||||
let payload = n.message || msg.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.', msg);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -42,12 +42,12 @@ module.exports = function(RED) {
|
||||
}
|
||||
|
||||
if(!node.server.isConnected()) {
|
||||
node.error("Matrix server connection is currently closed", {});
|
||||
node.error("Matrix server connection is currently closed", msg);
|
||||
node.send([null, msg]);
|
||||
}
|
||||
|
||||
if(!msg.userId) {
|
||||
node.error("msg.userId must be set to edit/create a user (ex: @user:server.com)", {});
|
||||
node.error("msg.userId must be set to edit/create a user (ex: @user:server.com)", msg);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -42,12 +42,12 @@ module.exports = function(RED) {
|
||||
}
|
||||
|
||||
if(!node.server.isConnected()) {
|
||||
node.error("Matrix server connection is currently closed", {});
|
||||
node.error("Matrix server connection is currently closed", msg);
|
||||
node.send([null, msg]);
|
||||
}
|
||||
|
||||
if(!msg.userId) {
|
||||
node.error("msg.userId must be set to edit/create a user (ex: @user:server.com)", {});
|
||||
node.error("msg.userId must be set to edit/create a user (ex: @user:server.com)", msg);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -41,18 +41,18 @@ module.exports = function(RED) {
|
||||
}
|
||||
|
||||
if(!node.server.isConnected()) {
|
||||
node.error("Matrix server connection is currently closed", {});
|
||||
node.error("Matrix server connection is currently closed", msg);
|
||||
node.send([null, msg]);
|
||||
}
|
||||
|
||||
msg.topic = node.roomId || 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", msg);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!msg.userId) {
|
||||
node.error("msg.userId is required to set user into a room", {});
|
||||
node.error("msg.userId is required to set user into a room", msg);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -27,12 +27,12 @@ module.exports = function(RED) {
|
||||
const { got } = await import('got');
|
||||
|
||||
if(!msg.payload.username) {
|
||||
node.error("msg.payload.username is required", {});
|
||||
node.error("msg.payload.username is required", msg);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!msg.payload.password) {
|
||||
node.error("msg.payload.password is required", {});
|
||||
node.error("msg.payload.password is required", msg);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -52,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', msg);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ module.exports = function(RED) {
|
||||
}
|
||||
|
||||
if(!node.server.isConnected()) {
|
||||
node.error("Matrix server connection is currently closed", {});
|
||||
node.error("Matrix server connection is currently closed", msg);
|
||||
node.send([null, msg]);
|
||||
}
|
||||
|
||||
|
@ -43,12 +43,12 @@ module.exports = function(RED) {
|
||||
}
|
||||
|
||||
if(!node.server.isConnected()) {
|
||||
node.error("Matrix server connection is currently closed", {});
|
||||
node.error("Matrix server connection is currently closed", msg);
|
||||
node.send([null, msg]);
|
||||
}
|
||||
|
||||
if(!msg.userId) {
|
||||
node.error("msg.userId must be set to get user whois data", {});
|
||||
node.error("msg.userId must be set to get user whois data", msg);
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user