Skip to content

Commit 58a33c9

Browse files
committed
added handling when credentials not found
1 parent 98a0c17 commit 58a33c9

2 files changed

Lines changed: 15 additions & 14 deletions

File tree

services/language_translation/v2.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
$('span#try-again').on('click', function() {
128128
oneditprepare();
129129
})
130-
130+
131131
// sorting functions
132132
function onlyUnique(value, index, self) {
133133
return self.indexOf(value) === index;
@@ -336,13 +336,14 @@
336336
selectAction();
337337
}).fail(function (err) {
338338
console.log(err);
339-
}).always(function (osef) {});
339+
}).always(function () {});
340340
}
341341

342342
function oneditprepare() {
343343
var node = this;
344344
$.getJSON('watson-translate/vcap/')
345345
.done(function (sids) {
346+
console.log(sids);
346347
$('.credentials').toggle(!sids);
347348
if (first_launch || !models) {
348349
$('#credentials-not-found').hide();

services/language_translation/v2.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,20 @@ module.exports = function (RED) {
2121

2222
temp.track();
2323

24-
var username, password, sUsername, sPassword, language_translation;
24+
var username, password, language_translation;
2525

2626
var service = cfenv.getAppEnv().getServiceCreds(/language translation/i);
2727

2828
if (service) {
29-
sUsername = service.username;
30-
sPassword = service.password;
29+
username = service.username;
30+
password = service.password;
3131
}
3232

3333
RED.httpAdmin.get('/watson-translate/vcap', function (req, res) {
34-
res.json(service ? {bound_service: true} : null);
35-
});
34+
res.json(service ? {
35+
bound_service: true
36+
} : null);
37+
});
3638

3739
RED.httpAdmin.get('/watson-translate/models', function (req, res) {
3840
language_translation = watson.language_translation({
@@ -67,11 +69,6 @@ module.exports = function (RED) {
6769
});
6870

6971
function SMTNode(config) {
70-
RED.nodes.createNode(this, config);
71-
var node = this;
72-
73-
username = sUsername || this.credentials.username;
74-
password = sPassword || this.credentials.password;
7572
this.on('input', function (msg) {
7673
var message = '';
7774

@@ -124,8 +121,8 @@ module.exports = function (RED) {
124121
var trainid = msg.trainid || config.trainid;
125122
var basemodel = msg.basemodel || config.basemodel;
126123

127-
username = sUsername || this.credentials.username;
128-
password = sPassword || this.credentials.password;
124+
username = username || this.credentials.username;
125+
password = password || this.credentials.password;
129126

130127
if (!username || !password) {
131128
this.status({
@@ -166,6 +163,9 @@ module.exports = function (RED) {
166163
}
167164
});
168165

166+
RED.nodes.createNode(this, config);
167+
var node = this;
168+
169169
this.doTranslate = function (msg, model_id) {
170170
node.status({
171171
fill: 'blue',

0 commit comments

Comments
 (0)