# Alert or navigate from HttpInterceptor

**URL:** <https://forum.ionicframework.com/t/alert-or-navigate-from-httpinterceptor/123004>\
**Category:** ionic-v3\
**Created:** [February 28, 2018, 5:11pm UTC](https://forum.ionicframework.com/t/alert-or-navigate-from-httpinterceptor/123004 "2018-02-28T17:11:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![douglapsley](https://avatars.discourse-cdn.com/v4/letter/d/a87d85/32.png) [@douglapsley](https://forum.ionicframework.com/u/douglapsley)\
**Post date:** [February 28, 2018, 5:11pm UTC](https://forum.ionicframework.com/t/alert-or-navigate-from-httpinterceptor/123004/1 "2018-02-28T17:11:04Z")

</div>

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?

```auto
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!

---

<div class="post-metadata">

**Author:** ![reedrichards](https://avatars.discourse-cdn.com/v4/letter/r/34f0e0/32.png) [@reedrichards](https://forum.ionicframework.com/u/reedrichards)\
**Post date:** [February 28, 2018, 6:19pm UTC](https://forum.ionicframework.com/t/alert-or-navigate-from-httpinterceptor/123004/2 "2018-02-28T18:19:27Z")

</div>

**UPDATE**

Just noticed now, this answer works with current Angular and `HttpClientModule` not `HttpModule` which you still seems to use.

Therefore only consider the service, subject and subscriber part.

_Interceptor with HttpClientModule:_

Have a look at an answer I gave on Stackoverflow. It was never marked as correct answer but I could confirm that I use it live in production.

Summarized, use a service, a subject and subscriber the forward the event from your interceptor till your app.component where you could then navigate.

> <https://stackoverflow.com/questions/48395610/load-component-from-interceptor/48403199#48403199>

---

<div class="post-metadata">

**Author:** ![douglapsley](https://avatars.discourse-cdn.com/v4/letter/d/a87d85/32.png) [@douglapsley](https://forum.ionicframework.com/u/douglapsley)\
**Post date:** [March 1, 2018, 12:12pm UTC](https://forum.ionicframework.com/t/alert-or-navigate-from-httpinterceptor/123004/3 "2018-03-01T12:12:34Z")

</div>

Thank you very much 🙂

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:48pm UTC](https://forum.ionicframework.com/t/alert-or-navigate-from-httpinterceptor/123004/4 "2021-07-19T21:48:38Z")

</div>

Closed on July 19, 2021, 9:48pm UTC


