Hi All,
I have been battling with this same issue for a while and can’t find a good answer or explanation on what I am meant to do. I might not have explained the issue well in the title, but essentially I am using RequireJS and I have a javascript page with the following relevant code:
define(['ojs/ojcore', 'knockout', 'jquery', 'dataService', 'mapping', 'appController', 'ojs/ojknockout', 'ojs/ojmodel', 'ojs/ojbutton', 'ojs/ojinputtext', 'ojs/ojmodule', 'ojs/ojknockout-validation', 'ojs/ojrouter', 'ojs/ojmoduleanimations'],
function (oj, ko, $, data, mapping, app) {
function LoginContentViewModel() {
var self = this;
self.username = ko.observable();
self.password = ko.observable();
self.tracker = ko.observable();
var login = data.login(self.username(), self.password());
login.done(function (response) {
// data.login(self.username, self.password).then(function (response) {
app.processUserProfile(response);
});
});
login.fail(function (response) {
**var test = data.retrieveError();**
** return data.retrieveError(response.status);**
});
};
}
return new LoginContentViewModel();
});
The relevant portion of the code is in the login.fail section. I am trying to call a function in an external js file that is defined in the define block above as data which represents the dataService file. When I do this I get the error “TypeError: data.retreieveError is not a function”. I know I must be way off base with my knowledge of scoping here, I have read countless articles but can’t seem to find anything that matches my issues. The file I am trying to call a function from dataservice/data has just a bunch of functions in it. This is the function I am trying to call:
function retrieveError(errorCode) {
switch (errorCode) {
case "400":
return "Bad Request - Invalid JSON Input";
case "403":
return "Authorization Failure - Invalid Credentials";
default:
return "Unknown Error " + errorCode;
}
}
How can I accomplish what I am trying to do? Thanks for your time, its much appreciated.