我有這個異步函數,它在promise中使用http.get。在http.get catch塊中拒絕承諾
private _getSchema(fileName): any {
return new Promise((resolve, reject) => {
this.http.get(fileName)
.map(this._extractData)
.catch(this._handleError)
.subscribe(schema => resolve(schema));
});
};
比在catch塊調用this._handleError相反,我想拒絕我的諾言,並通過拒絕錯誤對象。我怎麼做?
嘗試:
private _getSchema(fileName): any {
return new Promise((resolve, reject) => {
this.http.get(fileName)
.map(this._extractData)
.catch(err => reject(err))
.subscribe(schema => resolve(schema));
});
};
給出了錯誤:
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<{}>'.
我使用打字稿
只是'.catch(拒絕)'工作? – dandavis