HTTP call failed due to - Error: Not implemented JS: at NativeScriptDomAdapter.getCookie


#1

Hello,

I am a NS new-bee. Could you help to see what I am doing wrong:

##Code:
public login(username: string, password: string): Promise {
var self = this;
let body = ‘{“username”:"’ + username + ‘",’ + ‘“password”:"’ + password + ‘"}’;
let h = new Headers();
var promise = new Promise(resolve => {
self._httpService.post(HttpService.createUrl(Util.BeModule.Api, ‘/auth/token-auth’), body, { headers: h })
.map((resp: any) => AuthToken.asAuthToken(resp.json()))
.subscribe((at: AuthToken) => {
if (at.token) {
self._httpService.get(HttpService.createUrl(Util.BeModule.Api, ‘/actor/’ + username), undefined)
.map((res: any) => {
self._currentUser = Actor.asActor(res.json()); //set current user as actor
return CachedActor.asCachedActor(res.json()); // return cached actor
})
.subscribe((ca: CachedActor) => {
ca.token = at.token;
ca.exp = at.exp;
self._token = at.token;
self._tokenExpiration = at.exp;
self._couchbaseService.getDatabase().createDocument(ca, CachedActor.StorageKey);
return self.validateCurrentToken();
}, (err: any) => {
resolve(‘Failed to get Actor’);
});
} else {
resolve(‘Invalid name and password’);
}
}, (err: any) => {
resolve(‘Failed to log in’);
});
});
return promise;
}

##Error:
JS: ERROR Error: Uncaught (in promise): Error: Not implemented!
JS: Error: Not implemented!
JS: at NativeScriptDomAdapter.getCookie (file:///data/data/org.nativescript.mosmobile/files/app/tns_modules/nativescript-angular/dom-adapter.js:155:75) [angular]
JS: at CookieXSRFStrategy.configureRequest (file:///data/data/org.nativescript.mosmobile/files/app/tns_modules/@angular/http/bundles/http.umd.js:1330:77) [angular]
JS: at XHRBackend.createConnection (file:///data/data/org.nativescript.mosmobile/files/app/tns_modules/@angular/http/bundles/http.umd.js:1379:28) [angular]
JS: at httpRequest (file:///data/data/org.nativescript.mosmobile/files/app/tns_modules/@angular/http/bundles/http.umd.js:1762:20) [angular]
JS: at Http.request (file:///data/data/org.nativescript.mosmobile/files/app/tns_modules/@angular/http/bundles/http.umd.js:1872:34) [angular]
JS: at Http.post (file:///data/data/org.nativescript.mosmobile/files/app/tns_modules/@angular/http/bundles/http.umd.js:1896:21) [angular]
JS: at HttpService.post (file:///data/data/org.nativescript.mosmobile/files/app/shared/services/http-service.js:86:27) [angular]
JS: at file:///data/data/org.nativescript.mosmobile/files/app/shared/services/auth-service.js:56:31 [angular]
JS: at AuthService.login (file:///data/data/org.nativescript.mosmobile/files/app/shared/services/auth-service.js:55:23) [angular]
JS: at file:///data/data/org.nativescript.mosmobile/files/app/home/home.component.js:21:35 [angular]
JS: at Object.onInvoke (file:///data/data/org.nativescript.mosmobile/files/app/tns_modules/@angular/core/bundles/core.umd.js:4132:37) [angular]

Best Regards,


#2

Hey @lamqson,

Is the code executed on an iOS device, and is it by chance while the Chrome DevTools/Safari inspector were open and debugging the application? I might have an idea why this is happening, and how to fix it in a following nativescript release.


#3

You imported the wrong http module you need to import the one from
import { NativeScriptHttpModule } from "nativescript-angular/http";