I'm trying to check what exact error a request might throw by doing some custom checks and throw my own custom errors.
if let cause = resource.latestError?.cause {
if case RequestError.Cause.RequestCancelled = cause {
}
}
I get this error:
Argument type 'RequestError.Cause.RequestCancelled.Type' does not conform to expected type '_ErrorCodeProtocol'
Any ideas how I could check what the exact cause of the error is and then return my own custom errors?
Siesta’s error causes are open to extension and thus not an enum, so the
if case
syntax doesn’t work with them. (The compiler error you’re getting is because Swift thinks you’re trying to usecase
to extract an error code from an error that doesn’t have one.)Siesta’s error causes are instead a tree of distinct types. Instead of using
if case
, match error causes usingis
:…or simply:
…or if you need to assign the type-narrowed error to a variable so you can do something further with it: