0

I try to create cutom Http class to hadle 401 error globaly. I have error when call super constructor - Argument type RequestOptions is not assignable to parameter type RequestOptions.

Here is my code:

@Injectable()
export class HttpService extends Http {
  private baseUrl: string;

  constructor(baseUrl: string, backend: ConnectionBackend, options: RequestOptions) {
    this.baseUrl = baseUrl;
    super(backend, options); // <- Error here
  }

  get(url: string, options?: RequestOptionsArgs): Observable<Response> {
    console.log('get...');
    return super.get(this.baseUrl.concat(url), options).catch(this.handleError);
  }

  private handleError(error: Response | any) {
    console.log(error['status']);

    return Observable.throw(error);
  }
}
  • That looks correct. I have the same constructor in one of my classes and it works. Make sure you have everything all the right packages installed. That said, you have an unrelated error which is using `this` before calling `super()` – Aluan Haddad Dec 18 '16 at 19:50
  • I create new file with same code and appear new error - 'super' must be called before accessing 'this' in the constructor of a derived class. After I paste "super" before "this" everything works fine. Thanks – Roma Baida Dec 18 '16 at 21:04
  • Check out here https://stackoverflow.com/questions/39419987/angular2-provide-custom-http-not-working/46549420#46549420 – Rajkeshwar Prasad Oct 11 '17 at 09:05

0 Answers0