I'd like to put the error handling showed in the below example into a single function:

```
import { Injectable } from '@angular/core';
import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent } from '@angular/common/http';
import { Observable } from 'rxjs';
import { AuthService } from '../auth/auth.service';
import { tap, flatMap, concatMap } from 'rxjs/operators';
import { AlertController } from '@ionic/angular';

@Injectable()
export class ApiInterceptor implements HttpInterceptor {

    constructor(private auth: AuthService, private alertCon: AlertController) { }

    errorCodeToMessage = {
        500: "Internal server error has occurred. Please contact support.",
        404: "This resource can not be found. Please contact support.",
        403: "Access denied. Are you logged in?"
    };

    intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
        if(req.url != this.auth.LOGIN_URL && req.url != this.auth.REGISTRATION_URL)
            return this.auth.getToken()
            .pipe(
                concatMap((token: string) => {
                        req = req.clone({
                            setHeaders: {
                                'authorization': token
                            }
                        });
                    // Also handle errors globally
                    return next.handle(req).pipe(
                        tap(x => x, 
                            async (error) => {
                            const alert = await this.alertCon.create({
                                header: 'Error',
                                subHeader: null,
                                message: this.errorCodeToMessage[error.status],
                                buttons: ['OK']
                              });

                            await alert.present();
                        }
                        )
                    );
                }))
                ;
        else
            return next.handle(req).pipe(
                        tap(x => x, async (error) => {
                            console.log("the error is: ");
                            console.log(error);
                            const alert = await this.alertCon.create({
                                header: 'Error',
                                subHeader: null,
                                message: this.errorCodeToMessage[error.status],
                                buttons: ['OK']
                              });

                            await alert.present();
                        })
                    );
    }

}

```

However, when I do that, the injected AlertController no longer seems to be available.

```
import { Injectable } from '@angular/core';
import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent } from '@angular/common/http';
import { Observable } from 'rxjs';
import { AuthService } from '../auth/auth.service';
import { tap, flatMap, concatMap } from 'rxjs/operators';
import { AlertController } from '@ionic/angular';

@Injectable()
export class ApiInterceptor implements HttpInterceptor {

    constructor(private auth: AuthService, private alertCon: AlertController) { }

    errorCodeToMessage = {
        500: "Internal server error has occurred. Please contact support.",
        404: "This resource can not be found. Please contact support.",
        403: "Access denied. Are you logged in?"
    };

    async handleError(error) {
        console.log(error);
        const alert = await this.alertCon.create({
            header: 'Error',
            subHeader: null,
            message: this.errorCodeToMessage[error.status],
            buttons: ['OK']
          });

        await alert.present();
    }

    intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
        if(req.url != this.auth.LOGIN_URL && req.url != this.auth.REGISTRATION_URL)
            return this.auth.getToken()
            .pipe(
                concatMap((token: string) => {
                        req = req.clone({
                            setHeaders: {
                                'authorization': token
                            }
                        });
                    // Also handle errors globally
                    return next.handle(req).pipe(
                        tap(x => x, this.handleError)
                    );
                }))
                ;
        else
            return next.handle(req).pipe(
                        tap(x => x, this.handleError)
                    );
    }

}

```

Runtime error:

```
    ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'create' of undefined
TypeError: Cannot read property 'create' of undefined
    at TapSubscriber.<anonymous> (api.interceptor.ts:23)
    at step (tslib.es6.js:97)
    at Object.next (tslib.es6.js:78)
    at tslib.es6.js:71
    at new ZoneAwarePromise (zone.js:910)
    at Module.__awaiter (tslib.es6.js:67)
    at TapSubscriber.push../src/app/api/api.interceptor.ts.ApiInterceptor.handleError [as _tapError] (api.interceptor.ts:21)
    at TapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/tap.js.TapSubscriber._error (tap.js:55)
    at TapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.error (Subscriber.js:60)
    at XMLHttpRequest.onLoad (http.js:1640)
    at resolvePromise (zone.js:831)
    at new ZoneAwarePromise (zone.js:913)
    at Module.__awaiter (tslib.es6.js:67)
    at TapSubscriber.push../src/app/api/api.interceptor.ts.ApiInterceptor.handleError [as _tapError] (api.interceptor.ts:21)
    at TapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/tap.js.TapSubscriber._error (tap.js:55)
    at TapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.error (Subscriber.js:60)
    at XMLHttpRequest.onLoad (http.js:1640)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:423)
    at Object.onInvokeTask (core.js:17290)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:422)

```

I'm guessing it has something to do with being outside of the closure, but I may be wrong. Why is that happening and what can I do to get a single function to do the error handling?