import 'rxjs/add/observable/throw'; import 'rxjs/add/operator/catch'; import { Injectable, Injector } from '@angular/core'; import { HttpClient, HttpParams, HttpXhrBackend } from '@angular/common/http'; //import { Headers, Request, RequestOptions, RequestOptionsArgs, Response, HttpXHRBackend } from '@angular/common/http'; import { Router } from '@angular/router'; import { Observable } from 'rxjs/Observable'; import { WindowsAuthorizeService } from './windowsAuthorize.service'; @Injectable() export class ExtendedHttpService extends HttpClient { private router; private _authService: WindowsAuthorizeService; constructor(backend: HttpXhrBackend, defaultOptions: RequestOptions, private injector: Injector) { super(backend, defaultOptions); // this._authService = this.injector.get(WindowsAuthorizeService); } request(url: string | Request, options?: RequestOptionsArgs): Observable<Response> { return super.request(url, options).catch(this.catchErrors(url, options, 0)); } private catchErrors(url: string | Request, options?: RequestOptionsArgs, tryNumber?: number) { return (res: Response) => { if (this.router == null) { this.router = this.injector.get(Router); } if (this._authService == null) { this._authService = this.injector.get(WindowsAuthorizeService); } if (tryNumber < 10) { } return Observable.throw(res); }; } private setHeaders(objectToSetHeadersTo: Request | RequestOptionsArgs) { objectToSetHeadersTo.withCredentials = true; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)