2017-05-19 17 views
0

我基本上是創建一個事務。簡化描述如下:Rxjs條件錯誤流

1)作出承諾電話。 2)如果error和error.code ===「ConditionalCheckFailedException」,則忽略錯誤並繼續流而不更改。 3)如果錯誤,停止流。

以下給我1和3.如果我有一個特例,我想繼續使用流。那可能嗎? ...

目前,我有:

//... stream that works to this point 
.concatMap((item) => { 
    const insertions = Rx.Observable.fromPromise(AwsCall(item)) 
     .catch(e => { 
      if (e.code === "ConditionalCheckFailedException") { 
       return item 
      } else { 
       throw e; 
      } 
     }); 
    return insertions.map(() => item); 
}) 
.concat // ... much the same 
+0

謝謝你 - 真正的代碼被翻譯和錯過的變量。 –

+0

插入是一個承諾,對不對?但不是普通的承諾,因爲常規承諾沒有map方法...... insertions.map是做什麼的?它與「insertions」的承諾有什麼關係? –

+0

是的,AWS調用在返回時附加了.promise()。 「插入」是一個Rx.Observable.fromPromise。 –

回答

1

所以catch希望它提供了一個新的可觀察的功能。

相反,使用這樣的:

//... stream that works to this point 
.concatMap((item) => { 
    const insertions = Rx.Observable.fromPromise(AwsCall(item)) 
    .catch(e => e.code === "ConditionalCheckFailedException" 
     ? Rx.Observable.of(item) 
     : Rx.Observable.throw(e) 
    ) 
    /* depending on what AwsCall returns this might not be necessary: */ 
    .map(_ => item) 
    return insertions; 
}) 
.concat // ... much the same 

來源:http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#instance-method-catch