Last active
February 14, 2019 14:07
-
-
Save Oleg-Sulzhenko/2acfda010c539aa2e007a7271707b6b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
providers: [{ | |
provide: HTTP_INTERCEPTORS, | |
useClass: ErrorInterceptor, | |
multi: true, | |
}] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment