diff --git a/Cartfile.resolved b/Cartfile.resolved index fb60c25e3..3b326b430 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,4 +1,4 @@ -github "Alamofire/Alamofire" "4.7.0" +github "Alamofire/Alamofire" "4.7.1" github "AliSoftware/OHHTTPStubs" "f90c2bb0fb882e43761ab963ca8869d349d2c6e3" github "Quick/Nimble" "v7.0.3" github "Quick/Quick" "v1.2.0" diff --git a/Sources/Moya/Response.swift b/Sources/Moya/Response.swift index 81d9ff28a..b65dd769a 100644 --- a/Sources/Moya/Response.swift +++ b/Sources/Moya/Response.swift @@ -48,24 +48,13 @@ public extension Response { - statusCodes: The range of acceptable status codes. - throws: `MoyaError.statusCode` when others are encountered. */ - public func filter(statusCodes: ClosedRange) throws -> Response { + public func filter(statusCodes: R) throws -> Response where R.Bound == Int { guard statusCodes.contains(statusCode) else { throw MoyaError.statusCode(self) } return self } - /** - Returns the `Response` if the `statusCode` falls within the specified range. - - - parameters: - - statusCodes: The range of acceptable status codes. - - throws: `MoyaError.statusCode` when others are encountered. - */ - public func filter(statusCodes: Range) throws -> Response { - return try filter(statusCodes: statusCodes.lowerBound...statusCodes.upperBound-1) - } - /** Returns the `Response` if it has the specified `statusCode`. diff --git a/Sources/ReactiveMoya/SignalProducer+Response.swift b/Sources/ReactiveMoya/SignalProducer+Response.swift index ab871b4d9..b6dc5c5a7 100644 --- a/Sources/ReactiveMoya/SignalProducer+Response.swift +++ b/Sources/ReactiveMoya/SignalProducer+Response.swift @@ -8,14 +8,7 @@ import Moya extension SignalProducerProtocol where Value == Response, Error == MoyaError { /// Filters out responses that don't fall within the given range, generating errors when others are encountered. - public func filter(statusCodes: ClosedRange) -> SignalProducer { - return producer.flatMap(.latest) { response -> SignalProducer in - return unwrapThrowable { try response.filter(statusCodes: statusCodes) } - } - } - - /// Filters out responses that don't fall within the given range, generating errors when others are encountered. - public func filter(statusCodes: Range) -> SignalProducer { + public func filter(statusCodes: R) -> SignalProducer where R.Bound == Int { return producer.flatMap(.latest) { response -> SignalProducer in return unwrapThrowable { try response.filter(statusCodes: statusCodes) } } diff --git a/Sources/RxMoya/Observable+Response.swift b/Sources/RxMoya/Observable+Response.swift index 2bffca424..88481046f 100644 --- a/Sources/RxMoya/Observable+Response.swift +++ b/Sources/RxMoya/Observable+Response.swift @@ -8,14 +8,7 @@ import Moya extension ObservableType where E == Response { /// Filters out responses that don't fall within the given range, generating errors when others are encountered. - public func filter(statusCodes: ClosedRange) -> Observable { - return flatMap { response -> Observable in - return Observable.just(try response.filter(statusCodes: statusCodes)) - } - } - - /// Filters out responses that don't fall within the given range, generating errors when others are encountered. - public func filter(statusCodes: Range) -> Observable { + public func filter(statusCodes: R) -> Observable where R.Bound == Int { return flatMap { response -> Observable in return Observable.just(try response.filter(statusCodes: statusCodes)) } diff --git a/Sources/RxMoya/Single+Response.swift b/Sources/RxMoya/Single+Response.swift index c174ada18..e0a945e96 100644 --- a/Sources/RxMoya/Single+Response.swift +++ b/Sources/RxMoya/Single+Response.swift @@ -8,14 +8,7 @@ import RxSwift extension PrimitiveSequence where TraitType == SingleTrait, ElementType == Response { /// Filters out responses that don't fall within the given closed range, generating errors when others are encountered. - public func filter(statusCodes: ClosedRange) -> Single { - return flatMap { response -> Single in - return Single.just(try response.filter(statusCodes: statusCodes)) - } - } - - /// Filters out responses that don't fall within the given range, generating errors when others are encountered. - public func filter(statusCodes: Range) -> Single { + public func filter(statusCodes: R) -> Single where R.Bound == Int { return flatMap { response -> Single in return Single.just(try response.filter(statusCodes: statusCodes)) }