Http.request导致TypeError:“ values为null”

时间:2019-07-11 14:12:03

标签: angular local-storage angular-httpclient

我正在尝试从本地存储执行已保存的请求。

执行http.request()时返回以下错误: Error when subscribing on http.request()

这是负责发送请求的代码:

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()将保存的请求以本地存储形式返回为地图。

有人可以指出我的方向吗?我似乎找不到错误的根源。

0 个答案:

没有答案