import { Injectable } from '@angular/core';
import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/catch';
import 'rxjs/add/observable/throw';
@Injectable()
export class ErrorInterceptor implements HttpInterceptor {
constructor() { }
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
console.log('req ======= ', req.url);
const authReq = req.clone({ headers: req.headers.set('customHeader', 'customHeaderValue')});
return next.handle(req).catch((error) => {
console.log('Error Occurred', error);
return Observable.throw(error);
}) as any;
}
}