Skip to content

Commit

Permalink
Debug print updated
Browse files Browse the repository at this point in the history
  • Loading branch information
ks committed Feb 2, 2020
1 parent 78ccd64 commit 5975342
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 3 deletions.
Binary file removed .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
UserInterfaceState.xcuserstate
.DS_Store
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,34 @@
<dict>
<key>SchemeUserState</key>
<dict>
<key>CacheManager.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>2</integer>
</dict>
<key>SKHTTPClient-Package.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
<key>SKHTTPClient.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>SKHTTPClient</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>SKHTTPClientTests</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
Binary file modified Sources/.DS_Store
Binary file not shown.
Binary file modified Sources/SKHTTPClient/.DS_Store
Binary file not shown.
19 changes: 16 additions & 3 deletions Sources/SKHTTPClient/SKHTTPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ import Foundation
guard let statusCode = (urlResponse as? HTTPURLResponse)?.statusCode else { completion(nil, HTTPClientError(type: .invalidResponse)) ; return }

if self.printResponse {
print("URL : \(request.url?.absoluteString ?? "-")")
print("Status Code : \(statusCode)")
print(data?.prettyPrintedJSONString ?? "unable to print json-response")
self.printResponse(request, statusCode: statusCode, responseData: data)
}

guard Double(statusCode / 200) < 1.5 else { // all status codes begining with 2 are successfull
Expand Down Expand Up @@ -83,3 +81,18 @@ import Foundation
}.resume()
}
}

// MARK: - Helpers

extension HTTPClient {

private func printResponse(_ request: URLRequest, statusCode: Int, responseData: Data?) {
print("🌍 - Network Call : \(request.httpMethod ?? "-") -> \(request.url?.absoluteString ?? "-")")
let isNetworkCallSuccesfull: Bool = Double(statusCode / 200) < 1.5
let statusCodeEmoji: String = isNetworkCallSuccesfull ? "" : ""
print("\(statusCodeEmoji) - Status Code : \(statusCode)")

print(responseData?.prettyPrintedJSONString ?? "unable to print json-response")
print("\n")
}
}

0 comments on commit 5975342

Please sign in to comment.