case let .Failure(error):
print((error as NSError).localizedDescription)
print(Moya.Error.Underlying(error))
guard let error = error as? CustomStringConvertible else {
break
}
This is how my failure block looks.
On the first print as NSError, I get the following response:
The operation couldn’t be completed. (Moya.Error error 5.)
For the second print, underlying error:
Underlying(Moya.Error.Underlying(Error Domain=NSURLErrorDomain Code=-1 "(null)"))
I'm not sure what happened, it was working fine just few minutes back.
Any help is much appreciated! Thanks.
Hmm, hard to say what's happening without more code. The underlying error isn't too descriptive in this case.
Have you made any recent changes? Upgraded the library? Can you double-check the base URL?
Oh, forgot to say: sorry about this! We try to have descriptive errors. Thanks for opening the issue, we'll do our best to figure out what's going on :+1: \
Again, not sure what happened. It is working fine now!! I have done no changes.
Might be some network connection issue??
Well! Glad to hear it's working :smile: It must've been a network issue, since an error like that indicates that there is no response (otherwise, you'd get a status code and stuff).
I've been having the same problem. If a network error happens, I display the localized description to the user. But it always have the same error (The operation couldn’t be completed. (Moya.Error error 5.)).
Is there a way to Moya.Error provide the original network error? (e.g. Network seems to be down)
Hey there! Sorry you're having a problem – not sure which version of Moya you're using, but an error code of 5 suggests that you can access the underlying error. Check the source code out here: https://github.com/Moya/Moya/blob/master/Source/Error.swift
Oh. Thank you. This method is marked as deprecated. Will it have a replaced method? I'm using with rxSwift
That's strange, RxSwift should already be using the new error-handling. You can use the Swift case syntax to unwrap the enum and the underlying data: https://github.com/artsy/eidolon/blob/24e36a69bbafb4ef6dbe4d98b575ceb4e1d8345f/Kiosk/Bid%20Fulfillment/PlaceBidNetworkModel.swift#L49
Just to chime in here, what I think @aleufms understood was that he could use the nsError property of the Error. If it is true, yes this is deprecated as of now, but the discussion about it is still going on in #489.
Additionally, in your case you could just get the .Underlying(let error) case from the response error, as @ashfurrow mentioned. Having in mind your response error has a name responseError, you can get it as following:
if case .Underlying(let error) = responseError {
// Now you can use error property as an object of NSError
}
Hope it helps!
With @sunshinejr's comment, I think this is closed. Please re-open if not.
I am experiencing the above error, how to turn off the above message. I am using on swift version 2.3
I am experiencing the above error, how to turn off the above message. I am using on swift version 2.3
Most helpful comment
Just to chime in here, what I think @aleufms understood was that he could use the
nsErrorproperty of the Error. If it is true, yes this is deprecated as of now, but the discussion about it is still going on in #489.Additionally, in your case you could just get the
.Underlying(let error)case from the response error, as @ashfurrow mentioned. Having in mind your response error has a nameresponseError, you can get it as following:Hope it helps!