Skip to content

Commit

Permalink
[Issue Alamofire#732] Swapped out NSError for ErrorType in all Result…
Browse files Browse the repository at this point in the history
… types.
  • Loading branch information
cnoon committed Sep 3, 2015
1 parent 1bc35ab commit 64a0044
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 76 deletions.
2 changes: 1 addition & 1 deletion Source/Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public class Request {
let progress: NSProgress

var data: NSData? { return nil }
var error: NSError?
var error: ErrorType?

var credential: NSURLCredential?

Expand Down
2 changes: 1 addition & 1 deletion Source/ResponseSerialization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ extension Request {
*/
public func response(
queue queue: dispatch_queue_t? = nil,
completionHandler: (NSURLRequest?, NSHTTPURLResponse?, NSData?, NSError?) -> Void)
completionHandler: (NSURLRequest?, NSHTTPURLResponse?, NSData?, ErrorType?) -> Void)
-> Self
{
delegate.queue.addOperationWithBlock {
Expand Down
2 changes: 1 addition & 1 deletion Source/Upload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ extension Manager {
*/
public enum MultipartFormDataEncodingResult {
case Success(request: Request, streamingFromDisk: Bool, streamFileURL: NSURL?)
case Failure(NSError)
case Failure(ErrorType)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Source/Validation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extension Request {
*/
public enum ValidationResult {
case Success
case Failure(NSError)
case Failure(ErrorType)
}

/**
Expand Down
18 changes: 12 additions & 6 deletions Tests/AuthenticationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class BasicAuthenticationTestCase: AuthenticationTestCase {
var request: NSURLRequest?
var response: NSHTTPURLResponse?
var data: NSData?
var error: NSError?
var error: ErrorType?

// When
Alamofire.request(.GET, URLString)
Expand All @@ -78,7 +78,10 @@ class BasicAuthenticationTestCase: AuthenticationTestCase {
XCTAssertNil(response, "response should be nil")
XCTAssertNotNil(data, "data should not be nil")
XCTAssertNotNil(error, "error should not be nil")
XCTAssertEqual(error?.code ?? 0, -999, "error should be NSURLErrorDomain Code -999 'cancelled'")

if let code = (error as? NSError)?.code {
XCTAssertEqual(code, -999, "error should be NSURLErrorDomain Code -999 'cancelled'")
}
}

func testHTTPBasicAuthenticationWithValidCredentials() {
Expand All @@ -88,7 +91,7 @@ class BasicAuthenticationTestCase: AuthenticationTestCase {
var request: NSURLRequest?
var response: NSHTTPURLResponse?
var data: NSData?
var error: NSError?
var error: ErrorType?

// When
Alamofire.request(.GET, URLString)
Expand Down Expand Up @@ -130,7 +133,7 @@ class HTTPDigestAuthenticationTestCase: AuthenticationTestCase {
var request: NSURLRequest?
var response: NSHTTPURLResponse?
var data: NSData?
var error: NSError?
var error: ErrorType?

// When
Alamofire.request(.GET, URLString)
Expand All @@ -151,7 +154,10 @@ class HTTPDigestAuthenticationTestCase: AuthenticationTestCase {
XCTAssertNil(response, "response should be nil")
XCTAssertNotNil(data, "data should not be nil")
XCTAssertNotNil(error, "error should not be nil")
XCTAssertEqual(error?.code ?? 0, -999, "error should be NSURLErrorDomain Code -999 'cancelled'")

if let code = (error as? NSError)?.code {
XCTAssertEqual(code, -999, "error should be NSURLErrorDomain Code -999 'cancelled'")
}
}

func testHTTPDigestAuthenticationWithValidCredentials() {
Expand All @@ -161,7 +167,7 @@ class HTTPDigestAuthenticationTestCase: AuthenticationTestCase {
var request: NSURLRequest?
var response: NSHTTPURLResponse?
var data: NSData?
var error: NSError?
var error: ErrorType?

// When
Alamofire.request(.GET, URLString)
Expand Down
8 changes: 4 additions & 4 deletions Tests/DownloadTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class DownloadResponseTestCase: BaseTestCase {

var request: NSURLRequest?
var response: NSHTTPURLResponse?
var error: NSError?
var error: ErrorType?

// When
Alamofire.download(.GET, URLString, destination: destination)
Expand Down Expand Up @@ -165,7 +165,7 @@ class DownloadResponseTestCase: BaseTestCase {
var responseRequest: NSURLRequest?
var responseResponse: NSHTTPURLResponse?
var responseData: NSData?
var responseError: NSError?
var responseError: ErrorType?

// When
let download = Alamofire.download(.GET, URLString) { _, _ in
Expand Down Expand Up @@ -262,7 +262,7 @@ class DownloadResumeDataTestCase: BaseTestCase {
var request: NSURLRequest?
var response: NSHTTPURLResponse?
var data: AnyObject?
var error: NSError?
var error: ErrorType?

// When
let download = Alamofire.download(.GET, URLString, destination: destination)
Expand Down Expand Up @@ -295,7 +295,7 @@ class DownloadResumeDataTestCase: BaseTestCase {
var request: NSURLRequest?
var response: NSHTTPURLResponse?
var data: AnyObject?
var error: NSError?
var error: ErrorType?

// When
let download = Alamofire.download(.GET, URLString, destination: destination)
Expand Down
6 changes: 3 additions & 3 deletions Tests/RequestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class RequestResponseTestCase: BaseTestCase {
var request: NSURLRequest?
var response: NSHTTPURLResponse?
var data: NSData?
var error: NSError?
var error: ErrorType?

// When
Alamofire.request(.GET, URLString, parameters: ["foo": "bar"])
Expand Down Expand Up @@ -121,7 +121,7 @@ class RequestResponseTestCase: BaseTestCase {
var responseRequest: NSURLRequest?
var responseResponse: NSHTTPURLResponse?
var responseData: NSData?
var responseError: NSError?
var responseError: ErrorType?

// When
let request = Alamofire.request(.GET, URLString)
Expand Down Expand Up @@ -201,7 +201,7 @@ class RequestResponseTestCase: BaseTestCase {
var responseRequest: NSURLRequest?
var responseResponse: NSHTTPURLResponse?
var responseData: NSData?
var responseError: NSError?
var responseError: ErrorType?

// When
let request = Alamofire.request(.GET, URLString)
Expand Down
10 changes: 5 additions & 5 deletions Tests/ResponseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ class RedirectResponseTestCase: BaseTestCase {
var request: NSURLRequest?
var response: NSHTTPURLResponse?
var data: NSData?
var error: NSError?
var error: ErrorType?

// When
Alamofire.request(.GET, URLString)
Expand Down Expand Up @@ -332,7 +332,7 @@ class RedirectResponseTestCase: BaseTestCase {
var request: NSURLRequest?
var response: NSHTTPURLResponse?
var data: NSData?
var error: NSError?
var error: ErrorType?

// When
Alamofire.request(.GET, URLString)
Expand Down Expand Up @@ -372,7 +372,7 @@ class RedirectResponseTestCase: BaseTestCase {
var request: NSURLRequest?
var response: NSHTTPURLResponse?
var data: NSData?
var error: NSError?
var error: ErrorType?

// When
Alamofire.request(.GET, URLString)
Expand Down Expand Up @@ -412,7 +412,7 @@ class RedirectResponseTestCase: BaseTestCase {
var request: NSURLRequest?
var response: NSHTTPURLResponse?
var data: NSData?
var error: NSError?
var error: ErrorType?

// When
Alamofire.request(.GET, URLString)
Expand Down Expand Up @@ -454,7 +454,7 @@ class RedirectResponseTestCase: BaseTestCase {
var request: NSURLRequest?
var response: NSHTTPURLResponse?
var data: NSData?
var error: NSError?
var error: ErrorType?

// When
Alamofire.request(.GET, URLString)
Expand Down
Loading

0 comments on commit 64a0044

Please sign in to comment.