Skip to content

Commit

Permalink
Merge pull request #21 from naveen-c/master
Browse files Browse the repository at this point in the history
Marked all 2xx responses as valid
  • Loading branch information
abhishekfk committed Dec 30, 2019
2 parents 8581b25 + 2c558fe commit 08de56d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## [1.3.1](https://github.com/Flipkart/Swifty/releases/tag/1.3.1)
Released on 2019-12-30.

Swifty now handles all 2xx responses as valid responses.

## [1.3.0](https://github.com/Flipkart/Swifty/releases/tag/1.3.0)
Released on 2019-05-27.

Expand Down
14 changes: 2 additions & 12 deletions Sources/Core/ValidationInterceptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ import Foundation
/// Validation Interceptor
struct ValidationInterceptor: ResponseInterceptor {

/// Empty Status Codes
let emptyStatusCodes: Set<Int> = [204, 205]

/// Valid Status Codes
let validStatusCodes: [Int] = Array(200..<300)

Expand All @@ -37,16 +34,9 @@ struct ValidationInterceptor: ResponseInterceptor {
return response
}

/// Valid Empty Status Codes Check
if(response.data?.count == 0 && !emptyStatusCodes.contains(httpResponse.statusCode)){
response.fail(error: SwiftyError.responseValidation(reason: "Empty Data Received"))
return response
}

/// Data Nil Setting in case of Empty Status Code, instead of data with zero count
if(emptyStatusCodes.contains(httpResponse.statusCode)){
/// Do Not try to parse the empty data
if(response.data?.count == 0) {
response.succeed(response: response.response, data: nil)
// Do Not try to parse the empty data
response.parser = nil
return response
}
Expand Down
2 changes: 1 addition & 1 deletion Swifty.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Swifty'
s.version = '1.3.0'
s.version = '1.3.1'
s.summary = 'Lightweight & Fast Network Abstraction Layer for iOS'

s.description = <<-DESC
Expand Down

0 comments on commit 08de56d

Please sign in to comment.