Skip to content

Commit

Permalink
v0.8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
bhendersonizeni committed Jul 13, 2017
1 parent 5d508e4 commit 1262f43
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
v0.8.2
- Polished up connection error reporting

v0.8.1
- Made Diff's initializers public.
- Made Diff's initializers public

v0.8.0
- Added Reflector.copy and Reflector.diff
Expand Down
2 changes: 1 addition & 1 deletion Retrolux.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'Retrolux'
s.version = '0.8.1'
s.version = '0.8.2'
s.summary = 'An all in one networking solution, like Retrofit.'

# This description is used to generate tags and improve search results.
Expand Down
15 changes: 15 additions & 0 deletions Retrolux/Builder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ open class Builder {
}

if !response.isHttpStatusOk {
if response.urlResponse == nil, let error = response.error {
return .failure(ResponseError.connectionError(error))
}
return .failure(ResponseError.invalidHttpStatusCode(code: response.status))
}

Expand Down Expand Up @@ -275,6 +278,18 @@ open class Builder {
let body: ResponseType?
let error: Error?

if let error = clientResponse.error {
let response: Response<ResponseType> = Response(
request: request,
data: clientResponse.data,
error: error,
urlResponse: clientResponse.response,
body: nil,
interpreter: self.interpret
)
return response
}

if ResponseType.self == Void.self {
body = (() as! ResponseType)
error = nil
Expand Down
6 changes: 6 additions & 0 deletions Retrolux/ResponseError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Foundation

public enum ResponseError: RetroluxError {
case invalidHttpStatusCode(code: Int?)
case connectionError(Error)

public var rl_error: RetroluxErrorDescription {
switch self {
Expand All @@ -18,6 +19,11 @@ public enum ResponseError: RetroluxError {
description: code != nil ? "Unexpected HTTP status code, \(code!)." : "Expected an HTTP status code, but got no response.",
suggestion: nil
)
case .connectionError(let error):
return RetroluxErrorDescription(
description: error.localizedDescription,
suggestion: (error as NSError).localizedRecoverySuggestion ?? "Please check your Internet connection and try again."
)
}
}
}
27 changes: 27 additions & 0 deletions RetroluxTests/InterpretedResponseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,31 @@ class InterpretedResponseTests: XCTestCase {
}
}
}

func testNoInternet() {
let builder = Builder.dry()
let request = builder.makeRequest(
method: .get,
endpoint: "",
args: (),
response: Void.self
) { _ in
return ClientResponse(data: nil, response: nil, error: NSError(domain: "Whatever", code: 2, userInfo: [
NSLocalizedDescriptionKey: "Localized Description",
NSLocalizedRecoverySuggestionErrorKey: "Recovery Suggestion"
]))
}

switch request().perform().interpreted {
case .success:
XCTFail("Should not have succeeded.")
case .failure(let error):
if case ResponseError.connectionError = error {
XCTAssert(error.localizedDescription == "Localized Description")
XCTAssert((error as NSError).localizedRecoverySuggestion == "Recovery Suggestion")
} else {
XCTFail("Unexpected error code: \(error)")
}
}
}
}

0 comments on commit 1262f43

Please sign in to comment.