Skip to content

Commit 8b30a9a

Browse files
committed
Check for null result
1 parent ee5a2b5 commit 8b30a9a

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

OpenFlowNodeRED/src/node-red-contrib-openflow-storage.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ export class noderedcontribopenflowstorage {
403403
// await backupStore.set(filename, JSON.stringify(npmrc));
404404
if (WebSocketClient.instance.isConnected()) {
405405
const result = await NoderedUtil.Query("nodered", { _type: "npmrc", nodered_id: Config.nodered_id }, null, null, 1, 0, null, null, null, 1);
406-
if (result.length === 0) {
406+
if (NoderedUtil.IsNullUndefinded(result) || result.length === 0) {
407407
npmrc.name = "npmrc for " + Config.nodered_id;
408408
npmrc.nodered_id = Config.nodered_id;
409409
npmrc._type = "npmrc";
@@ -437,7 +437,7 @@ export class noderedcontribopenflowstorage {
437437
result = [];
438438
}
439439
const filename: string = Config.nodered_id + "_flows.json";
440-
if (result.length == 0) {
440+
if (NoderedUtil.IsNullUndefinded(result) || result.length == 0) {
441441
const json = await this.backupStore.get<string>(filename, null);
442442
if (!NoderedUtil.IsNullEmpty(json)) {
443443
this._flows = JSON.parse(json);
@@ -457,7 +457,7 @@ export class noderedcontribopenflowstorage {
457457
this.last_reload = new Date();
458458
const result = await NoderedUtil.Query("nodered", { _type: "flow", nodered_id: Config.nodered_id }, null, null, 1, 0, null, null, null, 1);
459459
this.last_reload = new Date();
460-
if (result.length === 0) {
460+
if (NoderedUtil.IsNullUndefinded(result) || result.length === 0) {
461461
const item: any = {
462462
name: "flows for " + Config.nodered_id,
463463
flows: JSON.stringify(flows), _type: "flow", nodered_id: Config.nodered_id
@@ -481,7 +481,7 @@ export class noderedcontribopenflowstorage {
481481
Logger.instanse.silly("noderedcontribopenflowstorage::_getCredentials");
482482
if (WebSocketClient.instance.isConnected()) {
483483
const result = await NoderedUtil.Query("nodered", { _type: "credential", nodered_id: Config.nodered_id }, null, null, 1, 0, null, null, null, 1);
484-
if (result.length === 0) { return []; }
484+
if (NoderedUtil.IsNullUndefinded(result) || result.length === 0) { return []; }
485485
cred = result[0].credentials;
486486
const arr: any = result[0].credentialsarray;
487487
if (arr !== null && arr !== undefined) {
@@ -531,7 +531,7 @@ export class noderedcontribopenflowstorage {
531531
}
532532
}
533533
if (credentials) {
534-
if (result.length === 0) {
534+
if (NoderedUtil.IsNullUndefinded(result) || result.length === 0) {
535535
const item: any = {
536536
name: "credentials for " + Config.nodered_id,
537537
credentials: credentials, credentialsarray: credentialsarray, _type: "credential", nodered_id: Config.nodered_id,
@@ -558,7 +558,7 @@ export class noderedcontribopenflowstorage {
558558
Logger.instanse.silly("noderedcontribopenflowstorage::_getSettings");
559559
if (WebSocketClient.instance.isConnected()) {
560560
const result = await NoderedUtil.Query("nodered", { _type: "setting", nodered_id: Config.nodered_id }, null, null, 1, 0, null, null, null, 1);
561-
if (result.length === 0) { return {}; }
561+
if (NoderedUtil.IsNullUndefinded(result) || result.length === 0) { return {}; }
562562
settings = JSON.parse(result[0].settings);
563563
}
564564
} catch (error) {
@@ -926,7 +926,7 @@ export class noderedcontribopenflowstorage {
926926
this.last_reload = new Date();
927927
const result = await NoderedUtil.Query("nodered", { _type: "setting", nodered_id: Config.nodered_id }, null, null, 1, 0, null, null, null, 1);
928928
this.last_reload = new Date();
929-
if (result.length === 0) {
929+
if (NoderedUtil.IsNullUndefinded(result) || result.length === 0) {
930930
const item: any = {
931931
name: "settings for " + Config.nodered_id,
932932
settings: JSON.stringify(settings), _type: "setting", nodered_id: Config.nodered_id
@@ -983,7 +983,7 @@ export class noderedcontribopenflowstorage {
983983
Logger.instanse.silly("noderedcontribopenflowstorage::_getSessions");
984984
if (WebSocketClient.instance.isConnected()) {
985985
const result = await NoderedUtil.Query("nodered", { _type: "session", nodered_id: Config.nodered_id }, null, null, 1, 0, null, null, null, 1);
986-
if (result.length === 0) { return []; }
986+
if (NoderedUtil.IsNullUndefinded(result) || result.length === 0) { return []; }
987987
item = JSON.parse(result[0].sessions);
988988
}
989989
} catch (error) {
@@ -1009,7 +1009,7 @@ export class noderedcontribopenflowstorage {
10091009
this.last_reload = new Date();
10101010
const result = await NoderedUtil.Query("nodered", { _type: "session", nodered_id: Config.nodered_id }, null, null, 1, 0, null, null, null, 1);
10111011
this.last_reload = new Date();
1012-
if (result.length === 0) {
1012+
if (NoderedUtil.IsNullUndefinded(result) || result.length === 0) {
10131013
const item: any = {
10141014
name: "sessions for " + Config.nodered_id,
10151015
sessions: JSON.stringify(sessions), _type: "session", nodered_id: Config.nodered_id
@@ -1047,7 +1047,7 @@ export class noderedcontribopenflowstorage {
10471047
Logger.instanse.silly("noderedcontribopenflowstorage::_getSessions");
10481048
if (WebSocketClient.instance.isConnected()) {
10491049
const result = await NoderedUtil.Query("nodered", { _type: "library", nodered_id: Config.nodered_id, type, path }, null, null, 1, 0, null, null, null, 1);
1050-
if (result.length === 0) { return null; }
1050+
if (NoderedUtil.IsNullUndefinded(result) || result.length === 0) { return null; }
10511051
var item = JSON.parse(result[0].sessions);
10521052
return item.body;
10531053
}

0 commit comments

Comments
 (0)