How to call the next swift combine publisher in turn if the previous one reported an error?

There are three publishers. First you need to try the first, if an error occurs, then use the second, if again an error, then use the third, if there is a failure, then return the last error. Important: you cannot call in parallel, it is necessary to follow the sequence. I have an assumption that the scan method should be used, but I do not understand how exactly.

Upvotes: 0

Views: 591

Answers (1)

New Dev
New Dev

Reputation: 49580

Catch is what allows you to return a publisher when an upstream error occurs. Generally speaking, the set-up would look like so:

publisher1
   .catch { err1 in
      publisher2
   }
   .catch { err2 in
      publisher3
   }

Upvotes: 1

Related Questions