Rxjs concat map 条件检查,然后再进行第二次调用

Rxjs concat map condition check before it go to second call

我想在继续之前检查第一次服务调用结果。如果第一次调用失败,我有事情要处理

    return this.http.get(this.partySiteAddressUrlOrganization + "?" + new Date().toString(), { params: newparams }).pipe(
  concatMap((result1: any) => {
    if (result1.success)
      return this.http.post(this.postRequestListURL, parm)
    else {
    }

  }));

没有完全理解你的问题,基于我的假设这里是我的想法

You want to handle the error/exception if any thrown from your API.

您可以简单地使用 rxjs/operators 中的 catchError 运算符并编写如下内容。

return this.http.get(this.partySiteAddressUrlOrganization + "?" + new Date().toString(), { params: newparams })
.pipe(
  concatMap((result1: any) => {
      return this.http.post(this.postRequestListURL, parm)
    }),
catchError((error)=>{
 // handle the error
 // if you want to throw it the throw other wise send the EMPTY its up to you
 // using return EMPTY;
}));

If first one is not your scenario and you are saying your API will return a flag if something is not right then you can handle this like

return this.http.get(this.partySiteAddressUrlOrganization + "?" + new Date().toString(), { params: newparams })
    .pipe(
      concatMap((result1: any) => {
          if(result1.success) {
             return this.http.post(this.postRequestListURL, parm)
         } else {
          // handle your stuff here and the return 
           return of({}); // {} can be your object 
         }
        }),
    catchError((error)=>{
     // handle the error
     // if you want to throw it the throw other wise send the EMPTY its up to you
    }));