我正在尝试从本地存储执行已保存的请求。
这是负责发送请求的代码:
public sync() {
this.setSyncState(SyncState.Syncing)
Array.from(this.stateManager.entries()).forEach(([key, value]) => {
let newRequest: HttpRequest<any> = { ...value }
this.http.request(
newRequest.method,
newRequest.urlWithParams,
{
body: newRequest.body,
headers: newRequest.headers,
params: newRequest.params,
reportProgress: newRequest.reportProgress,
responseType: newRequest.responseType,
withCredentials: newRequest.withCredentials
}
).subscribe(
event => {
if (event instanceof HttpResponse) {
this.stateManager.delete(key)
console.log("Request from cache succeeded")
}
},
error => {
console.log("Request from cache failed", error)
}
)
})
if (Array.from(this.stateManager.entries()).length < 0) {
this.setSyncState(SyncState.Synced)
} else {
this.setSyncState(SyncState.SyncFailed)
}
}
stateManager.entries()将保存的请求以本地存储形式返回为地图。
有人可以指出我的方向吗?我似乎找不到错误的根源。