Short description of the issue:
Observalbes emitting custom error objects
Description:
We have this class that represents an API error
public class APIResponseError : Error {
var code : Int?
var errors : [String]?
var message : String?
}
When the network services receives an error we want to emit this event, This is how i'm doing it
var apiError : APIResponseError!
//Configuring this error object
observer.on(Event.error(apiError))
Till now it's great.
But when we subscribe to this observable.
.subscribe(onNext: { (categories) in
self.categories = categories
self.setupPageView()
}, onError: { (error ) in
//Here I'm forced to parse it as APIResponseError
let errorObject = error as! APIResponseError
//handle the error
})
There should be an easier , cleaner way to emit custom error objects
Hi @wassimseif ,
if you need to parse the error, then you don't have a Rx error, but a special value case. You can use your enum or a Result as an element type.
If Swift compiler adds support for specifying generic error throwing constraints, then we can maybe consider some other options.
Alright! Got it, thanks
@kzaher : Any Update on this issue ??
Please read the discussion #1320.
There's no update yet, it won't happen in RxSwift 5 (maybe next version).
Most helpful comment
Hi @wassimseif ,
if you need to parse the error, then you don't have a Rx error, but a special value case. You can use your enum or a
Resultas an element type.If Swift compiler adds support for specifying generic error throwing constraints, then we can maybe consider some other options.