import { Injectable, Injector } from '@angular/core'
import {
HttpEvent,
HttpInterceptor,
HttpHandler,
HttpRequest
} from '@angular/common/http'
import { Observable } from 'rxjs/Observable'
import 'rxjs/add/observable/throw'
import 'rxjs/add/operator/catch'
@Injectable()
export class MyHttpInterceptor implements HttpInterceptor {
intercept(
req: HttpRequest<any>,
next: HttpHandler
): Observable<HttpEvent<any>> {
console.log('intercepted request ... ')
return next.handle(req).catch((error, caught) => {
// Проверяем код ошибки. Берём роутер и перенаправляем куда вам угодно.
return Observable.throw(error)
}) as any
}
}