add invalid response error case

This commit is contained in:
Ivan Smolin 2017-10-27 19:00:41 +03:00
parent a4c4cd00ae
commit b26932fbfe
2 changed files with 11 additions and 1 deletions

View File

@ -20,10 +20,13 @@
// THE SOFTWARE.
//
import Alamofire
public enum RequestError: Error {
case noConnection // no connection to the server
case network(error: Error)
case invalidResponse(error: AFError)
case mapping(error: Error, response: Any)
}

View File

@ -106,7 +106,14 @@ public extension Reactive where Base: DataRequest {
case .notConnectedToInternet, .timedOut:
throw RequestError.noConnection
default:
throw RequestError.network(error: $0)
throw RequestError.network(error: urlError)
}
case let afError as AFError:
switch afError {
case .responseSerializationFailed, .responseValidationFailed:
throw RequestError.invalidResponse(error: afError)
default:
throw RequestError.network(error: afError)
}
default:
throw RequestError.network(error: $0)