Questions about ObservableResource
FailLone opened this issue · 3 comments
Hi crimx:
Nice to see you updated for Suspense
,I love this update very much!!!!
When I study your code, I can't understand this Comment:
if (this.handler) {
const { resolve } = this.handler
this.handler = null
// Resolve instead of reject so that
// the resource itself won't throw error
resolve()
}
Could you tell me please:
- What this
reject
mean? - How do these code avoid
resouce itself throw error
?
Hi! By default error boundaries cannot catch callback errors. So errors of the resource are saved and re-thrown on read
as rendering errors which are then be captured by upper level error boundaries.
Also the reason why errors are not thrown through the suspender is that errors in Observables can occur at any moment even when Suspense is not triggered.
I guess the anwser I posted has been causing misunderstandings for others. Just to clearify a little bit:
the resource itself won't throw error
I was picking the worst word. By "resource" I acutally meant the "request", or the observable, not the observableResource instance.
Error from the observable is passed to the error observer callback which is uncatchable by error boundary. So it is saved and re-thrown on read()
as rendering error which then can be captured by upper level error boundaries.