Skip to content

Commit 9e60108

Browse files
committed
Merge pull request #81 from chughts/master
Fixed sequence of declarations
2 parents 696e873 + a8ab6db commit 9e60108

1 file changed

Lines changed: 25 additions & 25 deletions

File tree

  • services/language_translation

services/language_translation/v2.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,31 @@ module.exports = function (RED) {
104104
// have been provided.
105105
this.on('input', function (msg) {
106106

107+
var message = '';
108+
109+
// The dynamic nature of this node has caused problems with the password field. it is
110+
// hidden but not a credential. If it is treated as a credential, it gets lost when there
111+
// is a request to refresh the model list.
112+
//
113+
// Credentials are needed for each of the modes.
114+
115+
username = sUsername || this.credentials.username;
116+
password = sPassword || this.credentials.password || config.password;
117+
118+
if (!username || !password) {
119+
message = 'Missing Language Translation service credentials';
120+
node.error(message, msg);
121+
return;
122+
}
123+
124+
var action = msg.action || config.action;
125+
126+
if (!action) {
127+
node.warn('Missing action, please select one');
128+
node.send(msg);
129+
return;
130+
}
131+
107132
// This declaration put here, as codeacy wants it before it is used
108133
// in the do functions below.
109134
var language_translation = watson.language_translation({
@@ -270,37 +295,12 @@ module.exports = function (RED) {
270295
// Now that the do functions have been defined, can now determine what action this node
271296
// is configured for.
272297

273-
var message = '';
274-
275298
if (!msg.payload) {
276299
message = 'Missing property: msg.payload';
277300
node.error(message, msg);
278301
return;
279302
}
280303

281-
// The dynamic nature of this node has caused problems with the password field. it is
282-
// hidden but not a credential. If it is treated as a credential, it gets lost when there
283-
// is a request to refresh the model list.
284-
//
285-
// Credentials are needed for each of the modes.
286-
287-
username = sUsername || this.credentials.username;
288-
password = sPassword || this.credentials.password || config.password;
289-
290-
if (!username || !password) {
291-
message = 'Missing Language Translation service credentials';
292-
node.error(message, msg);
293-
return;
294-
}
295-
296-
var action = msg.action || config.action;
297-
298-
if (!action) {
299-
node.warn('Missing action, please select one');
300-
node.send(msg);
301-
return;
302-
}
303-
304304
// We have credentials, and know the mode. Further required fields checks
305305
// are specific to the requested action.
306306
// The required fields are checked, before the relevant function is invoked.

0 commit comments

Comments
 (0)