我已经扩展Http
类来设置默认标头并处理angular2应用内所有请求的错误,我想使用retryWhen()
重试某些错误的请求。
哪些错误retryWhen
会重试请求以及应该停止哪些错误?
@Injectable()
export class WpHttp extends Http {
constructor(backend: ConnectionBackend,
defaultOptions: RequestOptions,
private wpService: WpService) {
super(backend, defaultOptions);
}
get(endpoint: string, args?: QueryArgs): Observable<Response> {
return super.get(this.getUrl(endpoint, args), this.getOptions())
/** retry the request after 1 second */
.retryWhen(error => error.delay(1000))
/** timeout 3s
.timeout(3000 , new Error('delay exceeded'))
.catch((err) => {
if (err.status === 400 || err.status === 422) {
return Observable.throw(err);
}
else {
/** Stream errors in WpService */
this.wpService.errors.next(err);
}
})
.finally(() => {
});
}
}
它应该用于post
,put
,update
,delete
请求吗?