Zone js Unhandled Promise rejection

11.4k views Asked by At

I am receiving this error in Chrome dev tools console when calling a function in an external library on page load in my Angular application: "Unhandled Promise rejection: Cannot read properties of undefined (reading 'page') ' Zone: <root> ; Task: Promise.then ; Value: TypeError: Cannot read properties of undefined (reading 'page')". I get the error message in the console but the function still runs and works normally.

I have waited until the page has completed loading by checking to make sure to only call the function if the document.readyState is equal to complete and am still receiving this error. I am also receiving this error when putting the function in Angular lifecycle methods like ngOnInit, ngAfterViewInit, etc. I have even tried setTimeout for 30 seconds in ngOnInit and I am still getting this error message in the console.

The strange thing about this error is when I have the console open and refresh the page the error message disappears, but if I exit the dev tools, refresh the page, and reopen the console in the dev tools the error message is there again!

I'm thinking this has something to do with zone.js since the error message is disappearing with the dev tools open on page refresh and the function executes normally regardless of the error message appearing in the console or not. Has anyone encountered something like this before? What should I do to make this error message go away?

1

There are 1 answers

2
Birhan Nega On

If you have an api call that return a promise, You should catch block to handle errors

yourApiCallMethod().then((response)=>{}.catch(error=>{})

if you call .then but no catch you get this error