- 에러발생시 시퀀스가 종료하지 않도록 처리해야한다
- When you want to error out inside a flatMap operator, you should use throw as in regular Swift code
- default value로 처리하기
- 일반적으로 이전에 캐싱해놓은 값으로 처리
- Continues an observable sequence that is terminated by an error with the next observable sequence.
- Continues an observable sequence that is terminated by an error with a single element.
- 에러나면 다시 시도하기
- Repeats the source observable sequence until it successfully terminates.
- 될때까지 무한 시도
- Repeats the source observable sequence the specified number of times in case of an error or until it successfully terminates.
- 될때까지 제한된 시도
- Repeats the source observable sequence on error when the notifier emits a next value. If the source observable errors and the notifier completes, it will complete the source sequence.
- trigger 역할을 하는 handler 를 사용해서 에러를 정교하게 처리할 수 있다
let retryHandler: (Observable<Error>) -> Observable<Int> = { e in
return e.enumerated().flatMap{ (attempt, error) -> Observable<Int> in
if attempt >= maxAttempts - 1 {
return Observable.error(error)
}
print("== retry after \(attempt + 1) seconds ==")
return Observable<Int>.timer(Double(attempt + 1), scheduler: MainScheduler.instance).take(1)
}
}
- 에러났을 때 side effect 실행하기
- 에러시 화면에 메시지 표시하는 경
- 시퀀스의 모든 element를 next 이벤트로 감싸서 내보내주므로 에러가 발생해도 시퀀스가 종료되지 않게 한다