Skip to content

Instantly share code, notes, and snippets.

@Oleg-Sulzhenko
Last active February 14, 2019 14:07
Show Gist options
  • Save Oleg-Sulzhenko/2acfda010c539aa2e007a7271707b6b1 to your computer and use it in GitHub Desktop.
Save Oleg-Sulzhenko/2acfda010c539aa2e007a7271707b6b1 to your computer and use it in GitHub Desktop.
providers: [{
provide: HTTP_INTERCEPTORS,
useClass: ErrorInterceptor,
multi: true,
}]
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