private ping()

in src/app/connect/connect.service.ts [140:182]


    private ping(conn: ApiConnection, time2stop: number, force: boolean): Promise<any> {
        clearTimeout(this._pingTimeout);

        return this._client.get(conn, "/api").toPromise()
            .then(_ => {
                this.complete(conn);
                return Promise.resolve(conn);
            })
            .catch(e => {
                if (e.status == 403) {
                    this.error(conn, _ => this._notificationSvc.invalidAccessToken());
                    return Promise.reject("Could not connect: Unauthorized.");
                }
                else if (IsWAC && e.status == 0) {
                    return Promise.reject(ApiErrorType.Unreachable);
                }
                else {
                    return this._client.options(conn, "/api").toPromise()
                        .then(_ => {
                            // 
                            // It could be a race in between the initial GET and this OPTIONS, so try one more time
                            // If still fails, it's likely that an Integrated Authentication rejected the request
                            this._client.get(conn, "/api").toPromise()
                                .then(_ => this.complete(conn))
                                .catch(e => {
                                    if (force) {
                                        // Force ping loop so the connecting screen opens
                                        this._notificationSvc.unauthorized();
                                        return this.pingLoop(conn, time2stop);
                                    }
                                    else {
                                        // Notify that the user is unauthorized but don't force the connecting page
                                        this.error(conn, _ => this._notificationSvc.unauthorized())
                                        return Promise.reject("Could not connect: Unauthorized.");
                                    }
                                });
                        })
                        .catch(e => {
                            return this.pingLoop(conn, time2stop);
                        });
                }
            });
    }