Error or no error, I want to get into the subscribe success handler after retrying. To test, comment out the setTimeout line. This will make it so that checkforText$ always throws an error. I want to ignore the final error, and still return the editor to the subscribe success handler.
https://codepen.io/Spankid/pen/gOgVZEE
var editor = { innerText: "" }
var editorOpened$ = of(editor) // observe editor object
function checkforText(){
return new Promise((resolve,reject) => {
console.log('checking for text',editor)
if (editor.innerText == ""){
reject('No text');
} else {
resolve(editor)
}
})
}
var checkForText$ = defer( () => from(checkforText())) // observe text on editor object
// comment out this line out to test
setTimeout( _ => { editor.innerText = 'testing' }, 2000)
editorOpened$.pipe(
switchMap(editor =>
checkForText$.pipe(
retryWhen(errors => {
console.log ('no text found... retrying')
return errors.pipe(
delay(1000),
take(3),
)
}),
)
)
).subscribe(editor => {
console.log('FINISH CHECKING', editor)
}, err => console.log('ERROR ',err))
Output when text found (setTimeout not commented out):
checking for text {innerText: ""}
no text found... retrying
checking for text {innerText: ""}
checking for text {innerText: "testing"}
FINISH CHECKING {innerText: "testing"}
Target output when no text found (comment out setTimeout):
checking for text {innerText: ""}
no text found... retrying
checking for text {innerText: ""}
checking for text {innerText: ""}
checking for text {innerText: ""}
FINISH CHECKING {innerText: ""}
Actual output when no text found (comment out setTimeout):
checking for text {innerText: ""}
no text found... retrying
checking for text {innerText: ""}
checking for text {innerText: ""}
checking for text {innerText: ""}
I tried adding catchError after the retryWhen in hopes of making it into subscribe success handler. But it still does not. Any ideas?