Skip to content

Instantly share code, notes, and snippets.

@wotjd
Created October 29, 2019 01:59
Show Gist options
  • Save wotjd/2519902d4451a4c4fcd17ef0333db020 to your computer and use it in GitHub Desktop.
Save wotjd/2519902d4451a4c4fcd17ef0333db020 to your computer and use it in GitHub Desktop.
import Moya
import Foundation
guard let case MoyaError.underlying(nsError as NSError, _) = error else { return }
let unknownHostError = [
NSURLErrorUnknown,
NSURLErrorCannotFindHost,
NSURLErrorDomain,
NSURLErrorCancelled,
NSURLErrorNetworkConnectionLost,
NSURLErrorNotConnectedToInternet,
NSURLErrorDNSLookupFailed,
NSURLErrorBackgroundSessionWasDisconnected,
NSURLErrorCancelledReasonBackgroundUpdatesDisabled,
NSURLErrorBackgroundSessionInUseByAnotherProcess
]
if unknownHostError.contains(nsError.code) {
print("unknown host error")
} else if nsError.code == NSURLErrorTimedOut {
print("timed out")
} else {
print("unhandled error")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment