0

I was following this answer by Thierry Templier, but run into some troubles when defining error interceptors (other interceptors are working).

I have the following:

get(url: string, options?: RequestOptionsArgs): Observable<Response> {
  console.log('get...');
  return super.get(url, options).catch(res => {
    this.router.navigate(['Login']);
    return Observable.of(res)
  });
}

Which throws :

vendor.min.js:38333 ORIGINAL EXCEPTION: TypeError: _super.prototype.get.call(...).catch is not a function

Any ideas?

Community
  • 1
  • 1
uksz
  • 18,239
  • 30
  • 94
  • 161

1 Answers1

3

I think that you perhaps forgot the import the catch operator in the module where you define the interceptor class:

import 'rxjs/add/operator/catch';
Thierry Templier
  • 198,364
  • 44
  • 396
  • 360
  • 1
    Any idea why am I getting ' TypeError: result.subscribe is not a function' errors, (exactly the same example as in question) – uksz Mar 15 '16 at 13:01
  • 1
    I think that you could try this: `return Observable.of(res);` instead of `return res;` – Thierry Templier Mar 15 '16 at 13:03
  • amazing! where do you have all of this knowledge from? can you point any good books/articles? it seems like you are waaay ahead of curve :) – uksz Mar 15 '16 at 13:05
  • 1
    I played a lot with rxjs ;-) These two links could interest you: http://slides.com/robwormald/everything-is-a-stream and https://gist.github.com/staltz/868e7e9bc2a7b8c1f754. They are amazing! – Thierry Templier Mar 15 '16 at 13:18
  • whenever I am inside of my 'catch', I lose access to 'this'. Do you have any ideas on how to overcome this? – uksz Mar 17 '16 at 11:33
  • Thierry, do you mind looking at a follow up question here: http://stackoverflow.com/questions/36911993/intercepting-errors-and-subscribing-to ? – uksz Apr 28 '16 at 10:30