Angular2 RxJS 5.01升级TimeoutSubscriber报错
Angular2 RxJS 5.01 upgrade TimeoutSubscriber error
当我将 RxJS 从 5.0.0-rc.4 升级到 5.0.1 时,我的 HTTP 单元测试失败并显示 ..
TimeoutSubscriber
代码适用于 5.0.0-rc.4
这是失败的代码。任何想法表示赞赏。
private getHttpStream$(emit: any, url: string, httpResponseMapCallback: any, method: string) {
return this.http[method](url, emit, this.options)
.timeout(Config.http.timeout, new Error('timeout'))
.map((response: any) => {
if (response.status && !response.status.toString().startsWith(2)) {
return response;
}
// within the callback, emit provides access to the data emitted
return httpResponseMapCallback({emit, response});
})
.catch((err: any) => {
// Different code flow in real code v unit test code
/* istanbul ignore next */
if (err.status && err.statusText) {
return Observable.from([err]);
}
return Observable.from([err.message]);
});
}
从 beta/rc 到最终版本
的 .timeout(timeout, customErr, scheduler)
重载和自定义错误 has been removed. It was one of the last changes
将您的代码更改为:
return this.http[method](url, emit, this.options)
.timeout(Config.http.timeout)
或者如果您需要自定义错误:
return this.http[method](url, emit, this.options)
.timeout(Config.http.timeout)
.catch(err => err instanceof Rx.TimeoutError ? Rx.Observable.throw(new MyCustomError()) : Rx.Observable.throw(err))
当我将 RxJS 从 5.0.0-rc.4 升级到 5.0.1 时,我的 HTTP 单元测试失败并显示 ..
TimeoutSubscriber
代码适用于 5.0.0-rc.4
这是失败的代码。任何想法表示赞赏。
private getHttpStream$(emit: any, url: string, httpResponseMapCallback: any, method: string) {
return this.http[method](url, emit, this.options)
.timeout(Config.http.timeout, new Error('timeout'))
.map((response: any) => {
if (response.status && !response.status.toString().startsWith(2)) {
return response;
}
// within the callback, emit provides access to the data emitted
return httpResponseMapCallback({emit, response});
})
.catch((err: any) => {
// Different code flow in real code v unit test code
/* istanbul ignore next */
if (err.status && err.statusText) {
return Observable.from([err]);
}
return Observable.from([err.message]);
});
}
从 beta/rc 到最终版本
的.timeout(timeout, customErr, scheduler)
重载和自定义错误 has been removed. It was one of the last changes
将您的代码更改为:
return this.http[method](url, emit, this.options)
.timeout(Config.http.timeout)
或者如果您需要自定义错误:
return this.http[method](url, emit, this.options)
.timeout(Config.http.timeout)
.catch(err => err instanceof Rx.TimeoutError ? Rx.Observable.throw(new MyCustomError()) : Rx.Observable.throw(err))