Unrecognized selector sent to instance


#1

Relevant function in my view model looks like this:

viewModel.login = function () {
return fetchModule.fetch(config.apiUrl + “/api/getAppParameters”, {
method: “POST”,
body: JSON.stringify({
UserName: viewModel.get(“email”),
Password: viewModel.get(“password”),
AccountCode: viewModel.get(“accountcode”)
}),
headers: {
“Content-Type”: “application/json”
}
})
.then(handleErrors)
.then(function (response) {
return response.json();
})
.then(function (data) {
if (data.Status === “Success”) {
config.token = data.Data.TokenID;
viewModel.getStuff();
} else {
throw Error(“Your credentials are not valid.”);
}
});
};

Which I call like this:

exports.signIn = function () {
user.login()
.catch(function (errorString) {
dialogsModule.alert({
message: errorString,
okButtonText: “OK”
});
return Promise.reject(errorString);
})
.then(function () {
frameModule.topmost().navigate({
moduleName:“views/grid/grid”,
clearHistory: true
});
});
};

If the credentials are correct and the call returns with Status === Success, everything’s fine.
But dare you enter a wrong password!
Then you get this:

017-04-06 11:46:44.535 Hub[2294:1983059] -[__NSDictionaryI length]: unrecognized selector sent to instance 0x177331a0
2017-04-06 11:46:44.544 Hub[2294:1983059] *** JavaScript call stack:
(
0 UIApplicationMain@[native code]
1 start@file:///app/tns_modules/tns-core-modules/application/application.js:251:26
2 anonymous@file:///app/app.js:6:24
3 evaluate@[native code]
4 moduleEvaluation@:1:11
5 @:7:50
6 promiseReactionJob@:1:11
)
2017-04-06 11:46:44.545 Hub[2294:1983059] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[__NSDictionaryI length]: unrecognized selector sent to instance 0x177331a0’
*** First throw call stack:
(0x2268791b 0x21e22e17 0x2268d2b5 0x2268aee1 0x225b6238 0x26fe04f1 0x26fe065b 0x274474bd 0x26d08cd1 0x22e1ea35 0x22e1e437 0x22e1e1cd 0x22e2a0c5 0x26d0975d 0x22e1ddf9 0x26d0937d 0x26d095ab 0x26d09385 0x26bfdd37 0x26d096b9 0x22e1ddf9 0x26d0937d 0x26d095ab 0x26d09385 0x26bfdd37 0x26f15301 0x26d096b9 0x22e1ddf9 0x26d0937d 0x26d095ab 0x26d09385 0x26bfdd37 0x26d096b9 0x22e1ddf9 0x26d0937d 0x26d095ab 0x26d09385 0x26bfdd37 0x26d096b9 0x22e1ddf9 0x26d0937d 0x26d095ab 0x26d09385 0x26bfdd37 0x26d096b9 0x22e1ddf9 0x26d0937d 0x26d095ab 0x26d09385 0x26bfdd37 0x26bfd799 0x22e1ddf9 0x26bfd683 0x26c0a68d 0x26c0a00b 0x2704371f 0x26f53e93 0x26f51db3 0x26eab4c9 0x26eb77db 0x26bf5b1d 0x226496c9 0x226479cd 0x22647dff 0x22597229 0x22597015 0x23b87ac9 0x26c6b189 0xaae02c 0xaab4f9 0x5c2397 0x88f40f 0x88ee8b 0x8965ab 0x8965b7 0x890e61 0x84753f 0x829e7b 0x955213 0x5cf335 0x9c0e51 0xa2782f 0x896ce1 0x8965b7 0x8965b7 0x8965b7 0x890e61 0x84753f 0x829e7b 0x955307 0x9be2b7 0x5c8443 0x600a2f 0xb7adb 0x2223f873)
libc++abi.dylib: terminating with uncaught exception of type NSException

What gives?


#2

OK so I found this:

If an error is thrown during the promise response evaluation, it arrives into the catch handler as an Object, not as a String.

{
“line”: 135,
“column”: 20,
“sourceURL”: “file:///app/shared/view-models/user-view-model.js”
}

This of course crashes the app as the dialog.alert method expects a string. Maybe someone could explain this to me? Pretty please with a cherry on top?