Skip to content

Commit 3cae67c

Browse files
committed
Improve nodered errors
1 parent 4e091d1 commit 3cae67c

12 files changed

Lines changed: 69 additions & 72 deletions

File tree

OpenFlowNodeRED/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openiap/nodered",
3-
"version": "1.1.166",
3+
"version": "1.1.167",
44
"description": "Simple wrapper around NodeRed, RabbitMQ and MongoDB to support a more scaleable NodeRed implementation.\r Also the \"backend\" for [OpenRPA](https://github.com/skadefro/OpenRPA)",
55
"main": "index.js",
66
"scripts": {
@@ -25,7 +25,7 @@
2525
},
2626
"dependencies": {
2727
"@nodemailer/mailparser2": "^1.0.3",
28-
"@openiap/openflow-api": "^1.0.57",
28+
"@openiap/openflow-api": "^1.0.58",
2929
"async-retry": "^1.3.1",
3030
"body-parser": "^1.19.0",
3131
"command-line-args": "^5.1.1",

OpenFlowNodeRED/src/nodered/nodes/amqp_nodes.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export class amqp_consumer_node {
9393
this.connect();
9494
}
9595
} catch (error) {
96-
NoderedUtil.HandleError(this, error);
96+
NoderedUtil.HandleError(this, error, null);
9797
}
9898
}
9999
onsocketclose(message) {
@@ -120,7 +120,7 @@ export class amqp_consumer_node {
120120
this.websocket()._logger.info("registed amqp consumer as " + this.localqueue);
121121
this.node.status({ fill: "green", shape: "dot", text: "Connected " + this.localqueue });
122122
} catch (error) {
123-
NoderedUtil.HandleError(this, error);
123+
NoderedUtil.HandleError(this, error, null);
124124
}
125125
}
126126
async OnMessage(msg: any, ack: any) {
@@ -138,7 +138,7 @@ export class amqp_consumer_node {
138138
this.node.send(data);
139139
ack();
140140
} catch (error) {
141-
NoderedUtil.HandleError(this, error);
141+
NoderedUtil.HandleError(this, error, msg);
142142
}
143143
}
144144
async onclose(removed: boolean, done: any) {
@@ -187,7 +187,7 @@ export class amqp_publisher_node {
187187
this.connect();
188188
}
189189
} catch (error) {
190-
NoderedUtil.HandleError(this, error);
190+
NoderedUtil.HandleError(this, error, null);
191191
}
192192
}
193193
onsignedin() {
@@ -217,7 +217,7 @@ export class amqp_publisher_node {
217217
this.node.status({ fill: "green", shape: "dot", text: "Connected " + this.localqueue });
218218

219219
} catch (error) {
220-
NoderedUtil.HandleError(this, error);
220+
NoderedUtil.HandleError(this, error, null);
221221
}
222222
}
223223
async OnMessage(msg: any, ack: any) {
@@ -235,7 +235,7 @@ export class amqp_publisher_node {
235235
}
236236
ack();
237237
} catch (error) {
238-
NoderedUtil.HandleError(this, error);
238+
NoderedUtil.HandleError(this, error, msg);
239239
}
240240
}
241241
async oninput(msg: any) {
@@ -256,7 +256,7 @@ export class amqp_publisher_node {
256256
}
257257
this.node.status({ fill: "green", shape: "dot", text: "Connected " + this.localqueue });
258258
} catch (error) {
259-
NoderedUtil.HandleError(this, error);
259+
NoderedUtil.HandleError(this, error, msg);
260260
}
261261
}
262262
async onclose(removed: boolean, done: any) {
@@ -296,7 +296,7 @@ export class amqp_acknowledgment_node {
296296
this.node.send(msg);
297297
this.node.status({});
298298
} catch (error) {
299-
NoderedUtil.HandleError(this, error);
299+
NoderedUtil.HandleError(this, error, msg);
300300
}
301301
}
302302
onclose() {

OpenFlowNodeRED/src/nodered/nodes/api_nodes.ts

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class api_get_jwt {
7676
user.username = user.name;
7777
q.jwt = Crypt.createToken(user);
7878
} else {
79-
return NoderedUtil.HandleError(this, new Error("root signin not allowed"));
79+
return NoderedUtil.HandleError(this, "root signin not allowed", msg);
8080
}
8181
}
8282
this.node.status({ fill: "blue", shape: "dot", text: "Requesting token" });
@@ -94,7 +94,8 @@ export class api_get_jwt {
9494
this.node.status({});
9595
} catch (error) {
9696
let message = error.message ? error.message : error;
97-
this.node.error(new Error(message), msg);
97+
// this.node.error(new Error(message), msg);
98+
NoderedUtil.HandleError(this, message, msg);
9899
this.node.status({ fill: 'red', shape: 'dot', text: message.toString().substr(0, 32) });
99100
}
100101
}
@@ -143,9 +144,7 @@ export class api_get {
143144
try {
144145
this.config.orderby = JSON.parse(this.config.orderby);
145146
} catch (error) {
146-
(this as Red).error("Error parsing orderby", error);
147-
// this.node.er
148-
// NoderedUtil.HandleError(this, error);
147+
NoderedUtil.HandleError(this, "Error parsing orderby", msg);
149148
return;
150149
}
151150
}
@@ -166,9 +165,7 @@ export class api_get {
166165
try {
167166
this.config.projection = JSON.parse(this.config.projection);
168167
} catch (error) {
169-
(this as Red).error("Error parsing projection", error);
170-
// this.node.er
171-
// NoderedUtil.HandleError(this, error);
168+
NoderedUtil.HandleError(this, "Error parsing projection", msg);
172169
return;
173170
}
174171
}
@@ -203,7 +200,7 @@ export class api_get {
203200
this.node.send(msg);
204201
this.node.status({});
205202
} catch (error) {
206-
NoderedUtil.HandleError(this, error);
203+
NoderedUtil.HandleError(this, error, msg);
207204
}
208205
}
209206
onclose() {
@@ -270,15 +267,15 @@ export class api_add {
270267
const errors = data.filter(result => NoderedUtil.IsString(result) || (result instanceof Error));
271268
if (errors.length > 0) {
272269
for (let i: number = 0; i < errors.length; i++) {
273-
NoderedUtil.HandleError(this, errors[i]);
270+
NoderedUtil.HandleError(this, errors[i], msg);
274271
}
275272
}
276273
data = data.filter(result => !NoderedUtil.IsString(result) && !(result instanceof Error));
277274
NoderedUtil.saveToObject(msg, this.config.resultfield, data);
278275
this.node.send(msg);
279276
this.node.status({});
280277
} catch (error) {
281-
NoderedUtil.HandleError(this, error);
278+
NoderedUtil.HandleError(this, error, msg);
282279
}
283280
}
284281
onclose() {
@@ -345,7 +342,7 @@ export class api_addmany {
345342
this.node.send(msg);
346343
this.node.status({});
347344
} catch (error) {
348-
NoderedUtil.HandleError(this, error);
345+
NoderedUtil.HandleError(this, error, msg);
349346
}
350347
}
351348
onclose() {
@@ -414,15 +411,15 @@ export class api_update {
414411
const errors = data.filter(result => NoderedUtil.IsString(result) || (result instanceof Error));
415412
if (errors.length > 0) {
416413
for (let i: number = 0; i < errors.length; i++) {
417-
NoderedUtil.HandleError(this, errors[i]);
414+
NoderedUtil.HandleError(this, errors[i], msg);
418415
}
419416
}
420417
data = data.filter(result => !NoderedUtil.IsString(result) && !(result instanceof Error));
421418
NoderedUtil.saveToObject(msg, this.config.resultfield, data);
422419
this.node.send(msg);
423420
this.node.status({});
424421
} catch (error) {
425-
NoderedUtil.HandleError(this, error);
422+
NoderedUtil.HandleError(this, error, msg);
426423
}
427424
}
428425
onclose() {
@@ -492,15 +489,15 @@ export class api_addorupdate {
492489
const errors = data.filter(result => NoderedUtil.IsString(result) || (result instanceof Error));
493490
if (errors.length > 0) {
494491
for (let i: number = 0; i < errors.length; i++) {
495-
NoderedUtil.HandleError(this, errors[i]);
492+
NoderedUtil.HandleError(this, errors[i], msg);
496493
}
497494
}
498495
data = data.filter(result => !NoderedUtil.IsString(result) && !(result instanceof Error));
499496
NoderedUtil.saveToObject(msg, this.config.resultfield, data);
500497
this.node.send(msg);
501498
this.node.status({});
502499
} catch (error) {
503-
NoderedUtil.HandleError(this, error);
500+
NoderedUtil.HandleError(this, error, msg);
504501
}
505502
}
506503
onclose() {
@@ -558,13 +555,13 @@ export class api_delete {
558555
const errors = data.filter(result => NoderedUtil.IsString(result) || (result instanceof Error));
559556
if (errors.length > 0) {
560557
for (let i: number = 0; i < errors.length; i++) {
561-
NoderedUtil.HandleError(this, errors[i]);
558+
NoderedUtil.HandleError(this, errors[i], msg);
562559
}
563560
}
564561
this.node.send(msg);
565562
this.node.status({});
566563
} catch (error) {
567-
NoderedUtil.HandleError(this, error);
564+
NoderedUtil.HandleError(this, error, msg);
568565
}
569566
}
570567
onclose() {
@@ -628,7 +625,7 @@ export class api_deletemany {
628625
this.node.send(msg);
629626
this.node.status({ fill: "green", shape: "dot", text: "deleted " + affectedrows + " rows" });
630627
} catch (error) {
631-
NoderedUtil.HandleError(this, error);
628+
NoderedUtil.HandleError(this, error, msg);
632629
}
633630
}
634631
onclose() {
@@ -683,7 +680,7 @@ export class api_map_reduce {
683680
this.node.send(msg);
684681
this.node.status({});
685682
} catch (error) {
686-
NoderedUtil.HandleError(this, error);
683+
NoderedUtil.HandleError(this, error, msg);
687684
}
688685
}
689686
onclose() {
@@ -857,7 +854,7 @@ export class api_updatedocument {
857854
this.node.send(msg);
858855
this.node.status({});
859856
} catch (error) {
860-
NoderedUtil.HandleError(this, error);
857+
NoderedUtil.HandleError(this, error, msg);
861858
}
862859
}
863860
onclose() {
@@ -900,7 +897,7 @@ export class grant_permission {
900897
}
901898

902899
const result: any[] = await NoderedUtil.Query('users', { _id: this.config.targetid }, { name: 1 }, { name: -1 }, 1, 0, msg.jwt)
903-
if (result.length === 0) { return NoderedUtil.HandleError(this, "Target " + this.config.targetid + " not found "); }
900+
if (result.length === 0) { return NoderedUtil.HandleError(this, "Target " + this.config.targetid + " not found ", msg); }
904901
const found = result[0];
905902

906903
let data: any[] = [];
@@ -930,7 +927,7 @@ export class grant_permission {
930927
this.node.send(msg);
931928
this.node.status({});
932929
} catch (error) {
933-
NoderedUtil.HandleError(this, error);
930+
NoderedUtil.HandleError(this, error, msg);
934931
}
935932
}
936933
onclose() {
@@ -1001,7 +998,7 @@ export class revoke_permission {
1001998
this.node.send(msg);
1002999
this.node.status({});
10031000
} catch (error) {
1004-
NoderedUtil.HandleError(this, error);
1001+
NoderedUtil.HandleError(this, error, msg);
10051002
}
10061003
}
10071004
onclose() {
@@ -1051,7 +1048,7 @@ export class download_file {
10511048
this.node.send(msg);
10521049
this.node.status({});
10531050
} catch (error) {
1054-
NoderedUtil.HandleError(this, error);
1051+
NoderedUtil.HandleError(this, error, msg);
10551052
}
10561053
}
10571054
onclose() {
@@ -1094,7 +1091,7 @@ export class upload_file {
10941091
this.node.send(msg);
10951092
this.node.status({});
10961093
} catch (error) {
1097-
NoderedUtil.HandleError(this, error);
1094+
NoderedUtil.HandleError(this, error, msg);
10981095
}
10991096
}
11001097
onclose() {
@@ -1137,7 +1134,7 @@ export class api_aggregate {
11371134
this.node.send(msg);
11381135
this.node.status({});
11391136
} catch (error) {
1140-
NoderedUtil.HandleError(this, error);
1137+
NoderedUtil.HandleError(this, error, msg);
11411138
}
11421139
}
11431140
onclose() {
@@ -1203,7 +1200,7 @@ export class api_watch {
12031200
this.node.send(msg);
12041201
this.node.status({});
12051202
} catch (error) {
1206-
NoderedUtil.HandleError(this, error);
1203+
NoderedUtil.HandleError(this, error, msg);
12071204
}
12081205
}
12091206
async onclose(removed: boolean, done: any) {
@@ -1213,7 +1210,7 @@ export class api_watch {
12131210
await NoderedUtil.UnWatch(this.watchid, null);
12141211
}
12151212
} catch (error) {
1216-
NoderedUtil.HandleError(this, error);
1213+
NoderedUtil.HandleError(this, error, null);
12171214
}
12181215
this.watchid = null;
12191216
this.node.status({ text: "Not watching" });

OpenFlowNodeRED/src/nodered/nodes/googleauth_nodes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ export class googleauth_request {
228228
this.node.on('input', this.oninput);
229229
this.node.status({});
230230
} catch (error) {
231-
NoderedUtil.HandleError(this, error);
231+
NoderedUtil.HandleError(this, error, null);
232232
}
233233
}
234234

@@ -287,7 +287,7 @@ export class googleauth_request {
287287
}
288288
request(options, (error, response, body) => {
289289
if (error) {
290-
NoderedUtil.HandleError(this, error);
290+
NoderedUtil.HandleError(this, error, msg);
291291
return done();
292292
}
293293
msg.payload = body;
@@ -300,7 +300,7 @@ export class googleauth_request {
300300
}
301301
} catch (error) {
302302
done();
303-
NoderedUtil.HandleError(this, error);
303+
NoderedUtil.HandleError(this, error, msg);
304304
}
305305
}
306306
onclose() {

OpenFlowNodeRED/src/nodered/nodes/nodered_nodes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class get_pods {
2727
this.node.send(msg);
2828
this.node.status({});
2929
} catch (error) {
30-
NoderedUtil.HandleError(this, error);
30+
NoderedUtil.HandleError(this, error, msg);
3131
}
3232
}
3333
onclose() {

OpenFlowNodeRED/src/nodered/nodes/oauth2_nodes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class oauth2 {
6565
this.node.on("input", this.oninput);
6666
this.node.on("close", this.onclose);
6767
} catch (error) {
68-
NoderedUtil.HandleError(this, error);
68+
NoderedUtil.HandleError(this, error, null);
6969
}
7070
}
7171
async oninput(msg: any) {

OpenFlowNodeRED/src/nodered/nodes/onesignal_nodes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class create_notification {
5353
this.node.on("input", this.oninput);
5454
this.node.on("close", this.onclose);
5555
} catch (error) {
56-
NoderedUtil.HandleError(this, error);
56+
NoderedUtil.HandleError(this, error, null);
5757
}
5858
}
5959
async oninput(msg: any) {
@@ -101,12 +101,12 @@ export class create_notification {
101101
this.node.send(msg);
102102
} else {
103103
console.error('Error:', body.errors);
104-
NoderedUtil.HandleError(this, body.errors);
104+
NoderedUtil.HandleError(this, body.errors, msg);
105105
}
106106
}
107107
);
108108
} catch (error) {
109-
NoderedUtil.HandleError(this, error);
109+
NoderedUtil.HandleError(this, error, msg);
110110
}
111111
}
112112
onclose() {

0 commit comments

Comments
 (0)