对(未知URL)的角度奇怪的错误Http故障响应:0使用APP_INITIALIZER的未知错误

时间:2019-01-18 20:37:07

标签: angular firefox

我想在启动角度应用程序时使用APP_INITIALIZER从后端获取负载安全信息。我在APP_INITIALIZER中添加了AppModule

 providers: [
        {
            provide: APP_INITIALIZER,
            useFactory: init,
            deps: [AuthService],
            multi: true
        }
    ]

我的初始化函数:

export function init(authService: AuthService) {
    return () => {
        return authService.loadSecurityInfo(true).toPromise();
    };
}

方法loadSecurityInfo如下所示:

loadSecurityInfo(reconstituteSecurity = false): Observable<SecurityInfo> {
    console.log(`Loading SecurityInfo - Reconstitute security? ${reconstituteSecurity}`);

    return this.http
        .get<any>(this.securityInfoUrl, {headers: this.headers})
        .pipe(
            map(body => {
                this._securityInfo = new SecurityInfo();
                this._securityInfo.isAuthenticationEnabled = body.authenticationEnabled;
                this._securityInfo.isAuthenticated = body.authenticated;
                this._securityInfo.username = body.username;
                this._securityInfo.roles = body.roles as string[];

                console.log(`Getting security info: ${JSON.stringify(this.securityInfo)}`);
                return this._securityInfo;
            }),
            catchError(this.errorReporter.handleError('loadSecurityInfo', null))
        );
}

当我运行应用程序并尝试通过快速按两次F5刷新页面时,在浏览器控制台中出现错误:

Http failure response for (unknown url): 0 Unknown Error
loadSecurityInfo failed: Backend returned code 0, status: undefined, error list: undefined
zUnb/Y</e.prototype.handleError/<
http://localhost:8080/main.ba74b710245ba9a3c361.js:1:1433305
9Z1F/u</t.prototype.error
m
http://localhost:8080/polyfills.855d06b353079dbdbf17.js:1:20756
b

如果在刷新前一页时缓慢按F5键,则没有错误!我伤了脑筋,为什么会发生这个错误?在Firefox browser 60.4.0 esr和以下版本中,{strong>仅可能发生错误,并且在最新版本的FirefoxChrome上没有错误。任何帮助。

我使用Angular 6.1.10

0 个答案:

没有答案