Click here to Skip to main content
15,882,163 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I am updating angular 4 to 5 in my app
How to update below code?
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;

    }
}


What I have tried:

Tried HttpRequest object in place of RequestOptions
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900