Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 229654

Alert or navigate from HttpInterceptor

$
0
0

Hi all

Please see the following HttpInterceptor which checks for build version in the json returned from the server. I need to alert or navigate to another page or anything really, to let the user know if the build version of the app doesn’t match that on the back end server.

Any idea how I could get an alert to work, or navigate the user to another page etc please?

import { Injectable } from "@angular/core";
import { ConnectionBackend, RequestOptions, Request, RequestOptionsArgs, Response, Http, Headers, XHRBackend} from "@angular/http";
import { Observable } from "rxjs/Rx";


export function httpFactory(xhrBackend: XHRBackend, requestOptions: RequestOptions): Http {
    return new SMMEHttpInterceptor(xhrBackend, requestOptions);
}

@Injectable()
export class SMMEHttpInterceptor extends Http {
    constructor(
      backend: ConnectionBackend, 
      defaultOptions: RequestOptions
    ) {      
        super(backend, defaultOptions);
    }


    get(url: string, options?: RequestOptionsArgs): Observable<Response> {
        return super.get(url, options)
          .catch(this.onCatch)
          .do((res: Response) => {
            if(res.json().CURRENT_BUILD_VERSION != "1.0.3"){
              console.log("problem");
            }
          });
    }

    private onCatch(error: any, caught: Observable<any>): Observable<any> {
      return Observable.throw(error);
    }

}

It seems that a simple JavaScript alert fails on iOS. If there is a way of getting that to work then that would be fine. Just anything to display a message to the user.

Thanks!


Viewing all articles
Browse latest Browse all 229654

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>