The browser console displays the following error:
zone.js:668 Error: Uncaught (in promise): [object Undefined]
at resolvePromise (zone.js:814)
at resolvePromise (zone.js:771)
at zone.js:873
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188)
at drainMicroTaskQueue (zone.js:595)
at ZoneTask.push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (zone.js:500)
at invokeTask (zone.js:1540)
at globalZoneAwareCallback (zone.js:1577)
I have no idea where to look in the source code.
UPDATE: The same page opened under Firefox gives the message:
Error: Uncaught (in promise): [object Undefined]
Stack trace:
resolvePromise@http://localhost:4200/polyfills.js:3131:31
makeResolver/<@http://localhost:4200/polyfills.js:3041:17
setError@http://localhost:4200/scripts.js:979:21
messageCallback@http://localhost:4200/scripts.js:1092:25
./node_modules/zone.js/dist/zone.js/</ZoneDelegate.prototype.invokeTask@http://localhost:4200/polyfills.js:2738:17
./node_modules/zone.js/dist/zone.js/</Zone.prototype.runTask@http://localhost:4200/polyfills.js:2505:28
./node_modules/zone.js/dist/zone.js/</ZoneTask.invokeTask@http://localhost:4200/polyfills.js:2813:24
invokeTask@http://localhost:4200/polyfills.js:3857:9
globalZoneAwareCallback@http://localhost:4200/polyfills.js:3883:17
zone.js:668
UPDATE: In case the error is related to my newly added interceptor source code, here is how I handle a possible exception:
intercept(
request: HttpRequest<any>,
next: HttpHandler
): Observable<HttpEvent<any>> {
return this.addAuthHeader(request, next);
}
private addAuthHeader(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
console.log('=======>> Intercepting the http request to add the jwt token in the header');
const tokenPromise: Promise<any> = this.keycloakClientService.getToken();
const tokenObservable: Observable<any> = Observable.fromPromise(tokenPromise);
tokenObservable.map(authToken => {
console.log('Token value: ' + authToken);
// Clone the request before it is sent to the server
// as the original request is immutable and cannot be changed
request = request.clone({
setHeaders: {
'Authorization': AUTH_HEADER_PREFIX + authToken
}
});
console.log('=======>> The request has been cloned');
});
console.log('Handle the request in the interceptor chain');
return next.handle(request)
.catch(response => {
if (response instanceof HttpErrorResponse) {
if (response.status === 401) {
// TODO redirect to the login route or show a modal
}
console.log('The error has been handled by the interceptor', response);
}
return Observable.throw(response);
})
.do((response: HttpEvent<any>) => {
if (response instanceof HttpResponse) {
console.log('The response has been handled by the interceptor', response);
}
});
}