#How to prevent unsubscribe on observable error

14 messages · Page 1 of 1 (latest)

grave sigil
night dock
#

OTOH, once a subject (or any other observable) has errored, it won't ever emit again, which is why you're automatically unsubscribed. I guess it's not the subject which signals an error, but some other observable down the pipeline. You probably need to catch those errors. But without code, all we can do is guess.

boreal python
#

Ok im back lmao

#

async loadGridOpenSearch(openSearch: any): Promise<Document[]> {
if (openSearch === '' && openSearch.length > 3)
return [];
const response = this.prodoctivityService
.getDocumentsByKeywordValue(openSearch, false)
const dataPromise = lastValueFrom(response);
dataPromise.catch((error) => {
console.error(error);
return Promise.resolve([]);
});
const data = await dataPromise;
return data.map<Document>((document) => ({
filename: document.documentName,
createdBy: '',
documentType: document.documentType,
documentCategory: document.categoryName,
documentId: document.documentHandle,
modifiedDate: new Date().toDateString(),
}))
}

boreal python
#

@night dock

boreal python
night dock
#

There is no subscription, no Subject, no observable in the code you posted. So I have really no idea of what you're asking.

boreal python
#

Ojlh sorry i accidentally got banned

boreal python
#

this.data$ = this.dataSubject$.pipe(
debounceTime(500),
distinctUntilChanged(),
switchMap((result: any) => {
return concat(of({loading: true}), this.retrieveData(result));
}
),
retry(),
share()
)

night dock
#

So, let's say a new data is emitted by the subject, which causes retriveData to be called, and finally the new data, I guess, being displayed. Now another event is emitted from dataSubject, and retrieveData is called again, but fails with an error. What do you want to happen?

boreal python
#

i want it to not unsubscribe on error

night dock
#

That's not what I'm asking. Forget about the fact that you're a developer using RxJS. As a user of the application, what would you like to happen when retrieving the data fails?

boreal python
#

Getting an empty result

#

an empty array