Sridhar
Sridhar

Reputation: 101

Angular2 Rxjs Observable catch method compilation error

This line of typescript code is throwing an error when transpiling.

  getXXX(): Observable<any> {
    return this.http.get('api/xxx').catch(err => {return err});
  }

The error is

Supplied parameters do not match any signature of call target

I have the following imports in my script

import {Observable} from "rxjs/Rx";
import 'rxjs/add/operator/catch';

How doI fix it

Upvotes: 0

Views: 367

Answers (1)

Pengyy
Pengyy

Reputation: 38209

this is syntax error for Typescript. When arrow function has {}, in {} there must have a return, relevant link.

this.http.get('api/xxx').catch(err => { return err; });

or simply not use {}

this.http.get('api/xxx').catch(err => err);

Upvotes: 1

Related Questions