1- " use strict" ;
1+ ' use strict' ;
22var lib = require('./lib.js');
33
44module.exports = function (RED) { 
@@ -8,27 +8,31 @@ module.exports = function (RED) {
88        this.service = RED.nodes.getNode(config.service);
99        { {/hasServiceParams} 
1010        this.method = config.method;
11- 
1211        { {#methods} 
1312        { {#parameters} 
1413        this.{ {&methodName} { {&camelCaseName} { {&methodName} { {&camelCaseName} 
1514        this.{ {&methodName} { {&camelCaseName} { {&methodName} { {&camelCaseName} 
1615        { {/parameters} 
1716        { {/methods} 
18- 
1917        var node = this;
2018
2119        node.on('input', function (msg) { 
20+             var errorFlag = false ; 
2221            {{#domain}  }
2322            var client = new lib.{ {&className} 
2423            { {/domain} 
2524            { {^domain} 
26-             var client = new lib.{ {&className} {  domain: this.service.host } 
25+             var client;
26+             if (this.service && this.service.host) { 
27+                 client = new lib.{{&className}  }({  domain: this.service.host } 
28+             } else { 
29+                 node.error(' Host in configuration node is not specified.'  
30+                 errorFlag = true ; 
31+             }  
2732            { {/domain} 
28- 
2933            { {#isSecure} 
3034            { {#isSecureToken} 
31-             if (this.service && this.service.credentials && this.service.credentials.secureTokenValue) { 
35+             if (!errorFlag &&  this.service && this.service.credentials && this.service.credentials.secureTokenValue) { 
3236                if  (this.service.secureTokenIsQuery) { 
3337                    client.setToken(this.service.credentials.secureTokenValue, 
3438                                    this.service.secureTokenHeaderOrQueryName, true ); 
@@ -39,7 +43,7 @@ module.exports = function (RED) {
3943            }
4044            { {/isSecureToken} 
4145            { {#isSecureApiKey} 
42-             if (this.service && this.service.credentials && this.service.credentials.secureApiKeyValue) { 
46+             if (!errorFlag &&  this.service && this.service.credentials && this.service.credentials.secureApiKeyValue) { 
4347                if  (this.service.secureApiKeyIsQuery) { 
4448                    client.setApiKey(this.service.credentials.secureApiKeyValue, 
4549                                     this.service.secureApiKeyHeaderOrQueryName, true ); 
@@ -50,18 +54,18 @@ module.exports = function (RED) {
5054            }
5155            { {/isSecureApiKey} 
5256            { {#isSecureBasic} 
53-             if (this.service && this.service.credentials) { 
57+             if (!errorFlag &&  this.service && this.service.credentials) { 
5458                client.setBasicAuth(this.service.credentials.username, this.service.credentials.password); 
5559            }  
5660            { {/isSecureBasic} 
5761            { {/isSecure} 
58- 
59-             client.body = msg.payload;
62+             if (!errorFlag) { 
63+                 client.body = msg.payload; 
64+             }  
6065
6166            var result;
62-             var errorFlag = false;
6367            { {#methods} 
64-             if (node.method === '{ {&methodName} { 
68+             if (!errorFlag &&  node.method === '{ {&methodName} { 
6569                var parameters = [], nodeParam, nodeParamType; 
6670                {{#parameters}  }
6771                { {#isBodyParam} 
@@ -82,10 +86,14 @@ module.exports = function (RED) {
8286
8387                result = client.{ {&methodName} 
8488            }
85- 
8689            { {/methods} 
90+             if (!errorFlag && result === undefined) { 
91+                 node.error(' Method is not specified.'  
92+                 errorFlag = true ; 
93+             }  
94+ 
8795            if (!errorFlag) { 
88-                 node.status({ fill: " blue" " dot" " {{&className}}.status.requesting" }  );
96+                 node.status({ fill: ' blue' ' dot' ' {{&className}}.status.requesting' }  );
8997                result.then(function (response) { 
9098                    if  (response.body !==  null &&  response.body !==  undefined) { 
9199                        msg.payload = response.body; 
@@ -94,14 +102,13 @@ module.exports = function (RED) {
94102                    node.status({ } 
95103                }).catch(function (error) { 
96104                    node.error(error, msg); 
97-                     node.status({ fill: " red" " ring" " node-red:common.status.error" }  );
105+                     node.status({ fill: ' red' ' ring' ' node-red:common.status.error' }  );
98106                });
99107            }
100108        });
101109    }
102110
103-     RED.nodes.registerType("{ {&nodeName} { {&className} 
104- 
111+     RED.nodes.registerType('{ {&nodeName} { {&className} 
105112    { {#hasServiceParams} 
106113    function { {&className} { 
107114        RED.nodes.createNode(this, n); 
@@ -127,21 +134,21 @@ module.exports = function (RED) {
127134        { {/isSecure} 
128135    }
129136
130-     RED.nodes.registerType(" { {&nodeName} " , { {&className} { 
137+     RED.nodes.registerType(' { {&nodeName} ' , { {&className} { 
131138        credentials: { 
132139            {{#isSecure}  }
133140            { {#isSecureToken} 
134-             secureTokenValue: {  type: " password" } 
141+             secureTokenValue: {  type: ' password' } 
135142            { {/isSecureToken} 
136143            { {#isSecureApiKey} 
137-             secureApiKeyValue: {  type: " password" } 
144+             secureApiKeyValue: {  type: ' password' } 
138145            { {/isSecureApiKey} 
139146            { {#isSecureBasic} 
140-             username: {  type: " text" } 
141-             password: {  type: " password" } 
147+             username: {  type: ' text' } 
148+             password: {  type: ' password' } 
142149            { {/isSecureBasic} 
143150            { {/isSecure} 
144-             temp: {  type: " text" } 
151+             temp: {  type: ' text' } 
145152        }
146153    });
147154    { {/hasServiceParams} 
0 commit comments