diff --git a/AlamoRecord.podspec b/AlamoRecord.podspec index 7f47ed6..6eadaf0 100644 --- a/AlamoRecord.podspec +++ b/AlamoRecord.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = 'AlamoRecord' - s.version = '1.1.0' + s.version = '1.1.1' s.summary = 'An elegant Alamofire wrapper inspired by ActiveRecord.' s.description = <<-DESC AlamoRecord is a powerful yet simple framework that eliminates the often complex networking layer that exists between your networking framework and your application. AlamoRecord uses the power of AlamoFire, AlamofireObjectMapper and the concepts behind the ActiveRecord pattern to create a networking layer that makes interacting with your API easier than ever. diff --git a/AlamoRecord/Classes/RequestManager.swift b/AlamoRecord/Classes/RequestManager.swift index fc9a5b3..6bc1036 100644 --- a/AlamoRecord/Classes/RequestManager.swift +++ b/AlamoRecord/Classes/RequestManager.swift @@ -70,23 +70,25 @@ open class RequestManager: NSObject { } /** - Makes a request to the given URL - - parameter method: The HTTP method - - parameter url: The URL that conforms to URLProtocol - - parameter parameters: The parameters. `nil` by default - - parameter encoding: The parameter encoding. `URLEncoding.default` by default - - parameter headers: The HTTP headers. `nil` by default - - parameter success: The block to execute if the request succeeds - - parameter failure: The block to execute if the request fails + Makes a request to the given URL + - parameter method: The HTTP method + - parameter url: The URL that conforms to URLProtocol + - parameter parameters: The parameters. `nil` by default + - parameter encoding: The parameter encoding. `URLEncoding.default` by default + - parameter headers: The HTTP headers. `nil` by default + - parameter emptyBody: Wether or not the response will have an empty body. `false` by default + - parameter success: The block to execute if the request succeeds + - parameter failure: The block to execute if the request fails */ @discardableResult open func makeRequest(_ method: Alamofire.HTTPMethod, - url: U, - parameters: Parameters? = nil, - encoding: ParameterEncoding = URLEncoding.default, - headers: HTTPHeaders? = nil, - success: (() -> Void)?, - failure: ((E) -> Void)?) -> DataRequest { + url: U, + parameters: Parameters? = nil, + encoding: ParameterEncoding = URLEncoding.default, + headers: HTTPHeaders? = nil, + emptyBody: Bool = false, + success: (() -> Void)?, + failure: ((E) -> Void)?) -> DataRequest { return makeRequest(method, url: url, @@ -94,13 +96,23 @@ open class RequestManager: NSObject { encoding: encoding, headers: headers) .responseJSON { response in - + Logger.logFinishedResponse(response: response) - switch response.result { - case .success: + + guard emptyBody else { + switch response.result { + case .success: + self.onSuccess(success: success, response: response) + case .failure(let error): + self.onFailure(error: error, response: response, failure: failure) + } + return + } + + if response.response!.statusCode >= 200 && response.response!.statusCode <= 299 { self.onSuccess(success: success, response: response) - case .failure(let error): - self.onFailure(error: error, response: response, failure: failure) + } else { + self.onFailure(error: response.error!, response: response, failure: failure) } }