I have this asynchronous function which uses http.get inside a promise.
private _getSchema(fileName): any {
return new Promise((resolve, reject) => {
this.http.get(fileName)
.map(this._extractData)
.catch(this._handleError)
.subscribe(schema => resolve(schema));
});
};
Rather than call this._handleError in the catch block, I would like to reject my promise and pass reject the error object. How do I do that?
attempt:
private _getSchema(fileName): any {
return new Promise((resolve, reject) => {
this.http.get(fileName)
.map(this._extractData)
.catch(err => reject(err))
.subscribe(schema => resolve(schema));
});
};
gives error:
Argument of type '(err: any) => void' is not assignable to parameter of type '(err: any, caught: Observable) => ObservableInput<{}>'. Type 'void' is not assignable to type 'ObservableInput<{}>'.
I'm using typescript
.catch(reject)
work? – dandavis