Skip to content

Commit

Permalink
added try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
mblackstock committed Nov 20, 2020
1 parent cccadc3 commit ded38f8
Showing 1 changed file with 51 additions and 45 deletions.
96 changes: 51 additions & 45 deletions influxdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,59 +121,65 @@ module.exports = function (RED) {
node.error(RED._("influxdb.errors.nomeasurement"), msg);
return;
}
var point;
if (_.isArray(msg.payload) && msg.payload.length > 0) {
// array of arrays
if (_.isArray(msg.payload[0]) && msg.payload[0].length > 0) {
msg.payload.forEach(element => {
point = new Point(measurement);

var fields = element[0];
try {
if (_.isArray(msg.payload) && msg.payload.length > 0) {
// array of arrays
if (_.isArray(msg.payload[0]) && msg.payload[0].length > 0) {
msg.payload.forEach(element => {
let point = new Point(measurement);

let fields = element[0];
addFieldsToPoint(point, fields);

let tags = element[1];
for (const prop in tags) {
point.tag(prop, tags[prop]);
}
node.client.writePoint(point);
});
} else {
// array of non-arrays, assume one point with both fields and tags
let point = new Point(measurement);

let fields = msg.payload[0];
addFieldsToPoint(point, fields);

var tags = element[1];
const tags = msg.payload[1];
for (const prop in tags) {
point.tag(prop, tags[prop]);
}
node.client.writePoint(point);
});
} else {
// array of non-arrays, assume one point with both fields and tags
point = new Point(measurement);

var fields = msg.payload[0];
addFieldsToPoint(point, fields);

const tags = msg.payload[1];
for (const prop in tags) {
point.tag(prop, tags[prop]);

node.client.writePoint(point)
}

node.client.writePoint(point)
}
} else {
if (_.isPlainObject(msg.payload)) {
point = new Point(measurement);
var fields = msg.payload;
addFieldsToPoint(point, fields);
node.client.writePoint(point);
} else {
// just a value
point = new Point(measurement);
var value = msg.payload;
addFieldToPoint(point, 'value', value);
node.client.writePoint(point);
if (_.isPlainObject(msg.payload)) {
let point = new Point(measurement);
let fields = msg.payload;
addFieldsToPoint(point, fields);
node.client.writePoint(point);
} else {
// just a value
let point = new Point(measurement);
let value = msg.payload;
addFieldToPoint(point, 'value', value);
node.client.writePoint(point);
}
}

node.client
.close()
.catch(error => {
msg.influx_error = {
errorMessage: error
};
node.error(error, msg);
})
} catch (error) {
msg.influx_error = {
errorMessage: error
};
node.error(error, msg);
}

node.client
.close()
.catch(error => {
msg.influx_error = {
errorMessage: error
};
node.error(error, msg);
})
}

function queryRows(msg, node) {
Expand Down

0 comments on commit ded38f8

Please sign in to comment.