Resolver Emitting Error ` ERROR Error: “[object Object]” `

一曲冷凌霜 提交于 2019-11-30 06:01:12

This lack of detailed error occurred when using Mozilla Firefox. so what you need to do is to switch over to Google Chrome to see the specific error.

For more details check this link to learn more about it.

In console you can store errors like

ERROR Error: "[object Object]"

as global variable

and then get error message from object temp0.message

I have found solution for detailed error working in firefox. Its based on defining custom error handler and inspecting error properties yourself. After these steps, the errors were displayed properly, no need to switch to chrome.

  1. Define custom error handler class:
import { ErrorHandler } from '@angular/core'

export class MyErrorHandler implements ErrorHandler {

    handleError(error: any) {
        // console.error(Object.getOwnPropertyNames(error))
        // Object.getOwnPropertyNames(error).forEach(p => console.error(error[p]))
        console.error(error.fileName, error.lineNumber, ':', error.columnNumber, '\n', error.message, error.rejection)
    }

}
  1. Then register it as provider in main component
@NgModule({
    declarations: []
    imports: []
    providers: [{provide: ErrorHandler, useClass: MyErrorHandler}], // <-- register MyErrorHandler
    bootstrap: [RootComponent]
})
export class AppModule { }
resolve(route: ActivatedRouteSnapshot,
      state: RouterStateSnapshot): Observable<any> {
    return Observable.create((observer: Observer<any>) => {

      this.appInitService.init()
          .subscribe(data => {
            this.appInitService.preload();
            observer.next(data);
            observer.complete();
          });

    }).map(item => !!item)
}

The code above will work for you.

if your rxjs version is 6.x you will use .pipe(map(item => !!item))

This error comes due to wrong router declaration. Also exact error never going to come in Firefox. Check route file in chrome. #angularjs-route

The error could hide details on firefox if you build without --prod and host in web server, try to build with --prod if you are hosting on a web server to get details about the error.

one-time solution : find function defaultErrorLogger in dist/vendor.bundle.js and add:

for (var _i = 1; _i < arguments.length; _i++) {
    values[_i - 1] = arguments[_i];
}
console.log(arguments);
console.error.apply(console, values); code here

then refresh page without recompiling

Mainly this error is found when using database object from '@angular/fire'

this can be fixed by using this.db.object('/' + ....).subscribe(...)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!