Browse Source

Refactored Error logic due to conflicting Error protocol released in Xcode 8 beta 4.

Christian Noon 9 years ago
parent
commit
4f687613ea

+ 27 - 51
Source/Error.swift

@@ -24,65 +24,41 @@
 
 import Foundation
 
-/// The `Errors` struct provides a convenience for creating custom Alamofire NSErrors.
-public struct Errors {
-    /// The domain used for creating all Alamofire errors.
-    public static let Domain = "org.alamofire.error"
+/// The domain used for creating all Alamofire errors.
+public let ErrorDomain = "org.alamofire.error"
 
-    /// The custom error codes generated by Alamofire.
-    public enum Code: Int {
-        case inputStreamReadFailed           = -6000
-        case outputStreamWriteFailed         = -6001
-        case contentTypeValidationFailed     = -6002
-        case statusCodeValidationFailed      = -6003
-        case dataSerializationFailed         = -6004
-        case stringSerializationFailed       = -6005
-        case jsonSerializationFailed         = -6006
-        case propertyListSerializationFailed = -6007
-    }
-
-    /// Custom keys contained within certain NSError `userInfo` dictionaries generated by Alamofire.
-    public struct UserInfoKeys {
-        /// The content type user info key for a `.ContentTypeValidationFailed` error stored as a `String` value.
-        public static let ContentType = "ContentType"
-
-        /// The status code user info key for a `.StatusCodeValidationFailed` error stored as an `Int` value.
-        public static let StatusCode = "StatusCode"
-    }
-
-    /**
-        Creates an `NSError` with the given error code and failure reason.
-
-        - parameter code:          The error code.
-        - parameter failureReason: The failure reason.
+/// The custom error codes generated by Alamofire.
+public enum ErrorCode: Int {
+    case inputStreamReadFailed           = -6000
+    case outputStreamWriteFailed         = -6001
+    case contentTypeValidationFailed     = -6002
+    case statusCodeValidationFailed      = -6003
+    case dataSerializationFailed         = -6004
+    case stringSerializationFailed       = -6005
+    case jsonSerializationFailed         = -6006
+    case propertyListSerializationFailed = -6007
+}
 
-        - returns: An `NSError` with the given error code and failure reason.
-    */
-    @available(*, deprecated:3.4.0)
-    public static func errorWithCode(_ code: Code, failureReason: String) -> NSError {
-        return errorWithCode(code.rawValue, failureReason: failureReason)
-    }
+// MARK: -
 
-    /**
-        Creates an `NSError` with the given error code and failure reason.
+/// Custom keys contained within certain NSError `userInfo` dictionaries generated by Alamofire.
+public struct ErrorUserInfoKeys {
+    /// The content type user info key for a `.ContentTypeValidationFailed` error stored as a `String` value.
+    public static let ContentType = "ContentType"
 
-        - parameter code:          The error code.
-        - parameter failureReason: The failure reason.
+    /// The status code user info key for a `.StatusCodeValidationFailed` error stored as an `Int` value.
+    public static let StatusCode = "StatusCode"
+}
 
-        - returns: An `NSError` with the given error code and failure reason.
-    */
-    @available(*, deprecated:3.4.0)
-    public static func errorWithCode(_ code: Int, failureReason: String) -> NSError {
-        let userInfo = [NSLocalizedFailureReasonErrorKey: failureReason]
-        return NSError(domain: Domain, code: code, userInfo: userInfo)
-    }
+// MARK: -
 
-    static func error(domain: String = Errors.Domain, code: Code, failureReason: String) -> NSError {
-        return error(domain: domain, code: code.rawValue, failureReason: failureReason)
+extension NSError {
+    convenience init(domain: String = ErrorDomain, code: ErrorCode, failureReason: String) {
+        self.init(domain: domain, code: code.rawValue, failureReason: failureReason)
     }
 
-    static func error(domain: String = Errors.Domain, code: Int, failureReason: String) -> NSError {
+    convenience init(domain: String = ErrorDomain, code: Int, failureReason: String) {
         let userInfo = [NSLocalizedFailureReasonErrorKey: failureReason]
-        return NSError(domain: domain, code: code, userInfo: userInfo)
+        self.init(domain: domain, code: code, userInfo: userInfo)
     }
 }

+ 8 - 7
Source/MultipartFormData.swift

@@ -213,6 +213,7 @@ public class MultipartFormData {
     public func appendBodyPart(fileURL: URL, name: String) {
         let fileName = fileURL.lastPathComponent
         let pathExtension = fileURL.pathExtension
+
         if !fileName.isEmpty && !pathExtension.isEmpty {
             let mimeType = mimeTypeForPathExtension(pathExtension)
             appendBodyPart(fileURL: fileURL, name: name, fileName: fileName, mimeType: mimeType)
@@ -404,10 +405,10 @@ public class MultipartFormData {
 
         if FileManager.default.fileExists(atPath: fileURL.path) {
             let failureReason = "A file already exists at the given file URL: \(fileURL)"
-            throw Errors.error(domain: NSURLErrorDomain, code: NSURLErrorBadURL, failureReason: failureReason)
+            throw NSError(domain: NSURLErrorDomain, code: NSURLErrorBadURL, failureReason: failureReason)
         } else if !fileURL.isFileURL {
             let failureReason = "The URL does not point to a valid file: \(fileURL)"
-            throw Errors.error(domain: NSURLErrorDomain, code: NSURLErrorBadURL, failureReason: failureReason)
+            throw NSError(domain: NSURLErrorDomain, code: NSURLErrorBadURL, failureReason: failureReason)
         }
 
         let outputStream: NSOutputStream
@@ -416,7 +417,7 @@ public class MultipartFormData {
             outputStream = possibleOutputStream
         } else {
             let failureReason = "Failed to create an output stream with the given URL: \(fileURL)"
-            throw Errors.error(domain: NSURLErrorDomain, code: NSURLErrorCannotOpenFile, failureReason: failureReason)
+            throw NSError(domain: NSURLErrorDomain, code: NSURLErrorCannotOpenFile, failureReason: failureReason)
         }
 
         outputStream.open()
@@ -483,7 +484,7 @@ public class MultipartFormData {
                 encoded.append(buffer, count: bytesRead)
             } else if bytesRead < 0 {
                 let failureReason = "Failed to read from input stream: \(inputStream)"
-                error = Errors.error(domain: NSURLErrorDomain, code: .inputStreamReadFailed, failureReason: failureReason)
+                error = NSError(domain: NSURLErrorDomain, code: .inputStreamReadFailed, failureReason: failureReason)
                 break
             } else {
                 break
@@ -542,7 +543,7 @@ public class MultipartFormData {
                 try writeBuffer(&buffer, toOutputStream: outputStream)
             } else if bytesRead < 0 {
                 let failureReason = "Failed to read from input stream: \(inputStream)"
-                throw Errors.error(domain: NSURLErrorDomain, code: .inputStreamReadFailed, failureReason: failureReason)
+                throw NSError(domain: NSURLErrorDomain, code: .inputStreamReadFailed, failureReason: failureReason)
             } else {
                 break
             }
@@ -583,7 +584,7 @@ public class MultipartFormData {
 
                 if bytesWritten < 0 {
                     let failureReason = "Failed to write to output stream: \(outputStream)"
-                    throw Errors.error(domain: NSURLErrorDomain, code: .outputStreamWriteFailed, failureReason: failureReason)
+                    throw NSError(domain: NSURLErrorDomain, code: .outputStreamWriteFailed, failureReason: failureReason)
                 }
 
                 bytesToWrite -= bytesWritten
@@ -647,6 +648,6 @@ public class MultipartFormData {
 
     private func setBodyPartError(code: Int, failureReason: String) {
         guard bodyPartError == nil else { return }
-        bodyPartError = Errors.error(domain: NSURLErrorDomain, code: code, failureReason: failureReason)
+        bodyPartError = NSError(domain: NSURLErrorDomain, code: code, failureReason: failureReason)
     }
 }

+ 3 - 2
Source/Request.swift

@@ -372,8 +372,6 @@ public class Request {
     class DataTaskDelegate: TaskDelegate, URLSessionDataDelegate {
         var dataTask: URLSessionDataTask? { return task as? URLSessionDataTask }
 
-        private var totalBytesReceived: Int64 = 0
-        private var mutableData: Data
         override var data: Data? {
             if dataStream != nil {
                 return nil
@@ -382,6 +380,9 @@ public class Request {
             }
         }
 
+        private var totalBytesReceived: Int64 = 0
+        private var mutableData: Data
+
         private var expectedContentLength: Int64?
         private var dataProgress: ((bytesReceived: Int64, totalBytesReceived: Int64, totalBytesExpectedToReceive: Int64) -> Void)?
         private var dataStream: ((data: Data) -> Void)?

+ 5 - 5
Source/ResponseSerialization.swift

@@ -165,7 +165,7 @@ extension Request {
 
             guard let validData = data else {
                 let failureReason = "Data could not be serialized. Input data was nil."
-                let error = Errors.error(code: .dataSerializationFailed, failureReason: failureReason)
+                let error = NSError(code: .dataSerializationFailed, failureReason: failureReason)
                 return .failure(error)
             }
 
@@ -214,7 +214,7 @@ extension Request {
 
             guard let validData = data else {
                 let failureReason = "String could not be serialized. Input data was nil."
-                let error = Errors.error(code: .stringSerializationFailed, failureReason: failureReason)
+                let error = NSError(code: .stringSerializationFailed, failureReason: failureReason)
                 return .failure(error)
             }
 
@@ -232,7 +232,7 @@ extension Request {
                 return .success(string)
             } else {
                 let failureReason = "String could not be serialized with encoding: \(actualEncoding)"
-                let error = Errors.error(code: .stringSerializationFailed, failureReason: failureReason)
+                let error = NSError(code: .stringSerializationFailed, failureReason: failureReason)
                 return .failure(error)
             }
         }
@@ -286,7 +286,7 @@ extension Request {
 
             guard let validData = data, validData.count > 0 else {
                 let failureReason = "JSON could not be serialized. Input data was nil or zero length."
-                let error = Errors.error(code: .jsonSerializationFailed, failureReason: failureReason)
+                let error = NSError(code: .jsonSerializationFailed, failureReason: failureReason)
                 return .failure(error)
             }
 
@@ -345,7 +345,7 @@ extension Request {
 
             guard let validData = data, validData.count > 0 else {
                 let failureReason = "Property list could not be serialized. Input data was nil or zero length."
-                let error = Errors.error(code: .propertyListSerializationFailed, failureReason: failureReason)
+                let error = NSError(code: .propertyListSerializationFailed, failureReason: failureReason)
                 return .failure(error)
             }
 

+ 6 - 6
Source/Validation.swift

@@ -85,11 +85,11 @@ extension Request {
                 let failureReason = "Response status code was unacceptable: \(response.statusCode)"
 
                 let error = NSError(
-                    domain: Errors.Domain,
-                    code: Errors.Code.statusCodeValidationFailed.rawValue,
+                    domain: ErrorDomain,
+                    code: ErrorCode.statusCodeValidationFailed.rawValue,
                     userInfo: [
                         NSLocalizedFailureReasonErrorKey: failureReason,
-                        Errors.UserInfoKeys.StatusCode: response.statusCode
+                        ErrorUserInfoKeys.StatusCode: response.statusCode
                     ]
                 )
 
@@ -177,11 +177,11 @@ extension Request {
             }
 
             let error = NSError(
-                domain: Errors.Domain,
-                code: Errors.Code.contentTypeValidationFailed.rawValue,
+                domain: ErrorDomain,
+                code: ErrorCode.contentTypeValidationFailed.rawValue,
                 userInfo: [
                     NSLocalizedFailureReasonErrorKey: failureReason,
-                    Errors.UserInfoKeys.ContentType: contentType
+                    ErrorUserInfoKeys.ContentType: contentType
                 ]
             )
 

+ 29 - 29
Tests/ResponseSerializationTests.swift

@@ -27,7 +27,7 @@ import Foundation
 import XCTest
 
 class ResponseSerializationTestCase: BaseTestCase {
-    let error = NSError(domain: Alamofire.Errors.Domain, code: -10000, userInfo: nil)
+    let error = NSError(domain: ErrorDomain, code: -10000, userInfo: nil)
 
     // MARK: - Data Response Serializer Tests
 
@@ -58,8 +58,8 @@ class ResponseSerializationTestCase: BaseTestCase {
         XCTAssertNotNil(result.error, "result error should not be nil")
 
         if let error = result.error {
-            XCTAssertEqual(error.domain, Alamofire.Errors.Domain, "error domain should match expected value")
-            XCTAssertEqual(error.code, Alamofire.Errors.Code.dataSerializationFailed.rawValue, "error code should match expected value")
+            XCTAssertEqual(error.domain, ErrorDomain, "error domain should match expected value")
+            XCTAssertEqual(error.code, ErrorCode.dataSerializationFailed.rawValue, "error code should match expected value")
         } else {
             XCTFail("error should not be nil")
         }
@@ -78,7 +78,7 @@ class ResponseSerializationTestCase: BaseTestCase {
         XCTAssertNotNil(result.error, "result error should not be nil")
 
         if let error = result.error {
-            XCTAssertEqual(error.domain, Alamofire.Errors.Domain, "error domain should match expected value")
+            XCTAssertEqual(error.domain, ErrorDomain, "error domain should match expected value")
             XCTAssertEqual(error.code, self.error.code, "error code should match expected value")
         } else {
             XCTFail("error should not be nil")
@@ -100,8 +100,8 @@ class ResponseSerializationTestCase: BaseTestCase {
         XCTAssertNotNil(result.error, "result error should not be nil")
 
         if let error = result.error {
-            XCTAssertEqual(error.domain, Alamofire.Errors.Domain, "error domain should match expected value")
-            XCTAssertEqual(error.code, Alamofire.Errors.Code.dataSerializationFailed.rawValue, "error code should match expected value")
+            XCTAssertEqual(error.domain, ErrorDomain, "error domain should match expected value")
+            XCTAssertEqual(error.code, ErrorCode.dataSerializationFailed.rawValue, "error code should match expected value")
         } else {
             XCTFail("error should not be nil")
         }
@@ -141,8 +141,8 @@ class ResponseSerializationTestCase: BaseTestCase {
         XCTAssertNotNil(result.error, "result error should not be nil")
 
         if let error = result.error {
-            XCTAssertEqual(error.domain, Alamofire.Errors.Domain, "error domain should match expected value")
-            XCTAssertEqual(error.code, Alamofire.Errors.Code.stringSerializationFailed.rawValue, "error code should match expected value")
+            XCTAssertEqual(error.domain, ErrorDomain, "error domain should match expected value")
+            XCTAssertEqual(error.code, ErrorCode.stringSerializationFailed.rawValue, "error code should match expected value")
         } else {
             XCTFail("error should not be nil")
         }
@@ -220,8 +220,8 @@ class ResponseSerializationTestCase: BaseTestCase {
         XCTAssertNotNil(result.error, "result error should not be nil")
 
         if let error = result.error {
-            XCTAssertEqual(error.domain, Alamofire.Errors.Domain, "error domain should match expected value")
-            XCTAssertEqual(error.code, Alamofire.Errors.Code.stringSerializationFailed.rawValue, "error code should match expected value")
+            XCTAssertEqual(error.domain, ErrorDomain, "error domain should match expected value")
+            XCTAssertEqual(error.code, ErrorCode.stringSerializationFailed.rawValue, "error code should match expected value")
         } else {
             XCTFail("error should not be nil")
         }
@@ -247,8 +247,8 @@ class ResponseSerializationTestCase: BaseTestCase {
         XCTAssertNotNil(result.error, "result error should not be nil")
 
         if let error = result.error {
-            XCTAssertEqual(error.domain, Alamofire.Errors.Domain, "error domain should match expected value")
-            XCTAssertEqual(error.code, Alamofire.Errors.Code.stringSerializationFailed.rawValue, "error code should match expected value")
+            XCTAssertEqual(error.domain, ErrorDomain, "error domain should match expected value")
+            XCTAssertEqual(error.code, ErrorCode.stringSerializationFailed.rawValue, "error code should match expected value")
         } else {
             XCTFail("error should not be nil")
         }
@@ -267,7 +267,7 @@ class ResponseSerializationTestCase: BaseTestCase {
         XCTAssertNotNil(result.error, "result error should not be nil")
 
         if let error = result.error {
-            XCTAssertEqual(error.domain, Alamofire.Errors.Domain, "error domain should match expected value")
+            XCTAssertEqual(error.domain, ErrorDomain, "error domain should match expected value")
             XCTAssertEqual(error.code, self.error.code, "error code should match expected value")
         } else {
             XCTFail("error should not be nil")
@@ -289,8 +289,8 @@ class ResponseSerializationTestCase: BaseTestCase {
         XCTAssertNotNil(result.error, "result error should not be nil")
 
         if let error = result.error {
-            XCTAssertEqual(error.domain, Alamofire.Errors.Domain, "error domain should match expected value")
-            XCTAssertEqual(error.code, Alamofire.Errors.Code.stringSerializationFailed.rawValue, "error code should match expected value")
+            XCTAssertEqual(error.domain, ErrorDomain, "error domain should match expected value")
+            XCTAssertEqual(error.code, ErrorCode.stringSerializationFailed.rawValue, "error code should match expected value")
         } else {
             XCTFail("error should not be nil")
         }
@@ -330,8 +330,8 @@ class ResponseSerializationTestCase: BaseTestCase {
         XCTAssertNotNil(result.error, "result error should not be nil")
 
         if let error = result.error {
-            XCTAssertEqual(error.domain, Alamofire.Errors.Domain, "error domain should match expected value")
-            XCTAssertEqual(error.code, Alamofire.Errors.Code.jsonSerializationFailed.rawValue, "error code should match expected value")
+            XCTAssertEqual(error.domain, ErrorDomain, "error domain should match expected value")
+            XCTAssertEqual(error.code, ErrorCode.jsonSerializationFailed.rawValue, "error code should match expected value")
         } else {
             XCTFail("error should not be nil")
         }
@@ -350,8 +350,8 @@ class ResponseSerializationTestCase: BaseTestCase {
         XCTAssertNotNil(result.error, "result error should not be nil")
 
         if let error = result.error {
-            XCTAssertEqual(error.domain, Alamofire.Errors.Domain, "error domain should match expected value")
-            XCTAssertEqual(error.code, Alamofire.Errors.Code.jsonSerializationFailed.rawValue, "error code should match expected value")
+            XCTAssertEqual(error.domain, ErrorDomain, "error domain should match expected value")
+            XCTAssertEqual(error.code, ErrorCode.jsonSerializationFailed.rawValue, "error code should match expected value")
         } else {
             XCTFail("error should not be nil")
         }
@@ -405,7 +405,7 @@ class ResponseSerializationTestCase: BaseTestCase {
         XCTAssertNotNil(result.error, "result error should not be nil")
 
         if let error = result.error {
-            XCTAssertEqual(error.domain, Alamofire.Errors.Domain, "error domain should match expected value")
+            XCTAssertEqual(error.domain, ErrorDomain, "error domain should match expected value")
             XCTAssertEqual(error.code, self.error.code, "error code should match expected value")
         } else {
             XCTFail("error should not be nil")
@@ -427,8 +427,8 @@ class ResponseSerializationTestCase: BaseTestCase {
         XCTAssertNotNil(result.error, "result error should not be nil")
 
         if let error = result.error {
-            XCTAssertEqual(error.domain, Alamofire.Errors.Domain, "error domain should match expected value")
-            XCTAssertEqual(error.code, Alamofire.Errors.Code.jsonSerializationFailed.rawValue, "error code should match expected value")
+            XCTAssertEqual(error.domain, ErrorDomain, "error domain should match expected value")
+            XCTAssertEqual(error.code, ErrorCode.jsonSerializationFailed.rawValue, "error code should match expected value")
         } else {
             XCTFail("error should not be nil")
         }
@@ -468,8 +468,8 @@ class ResponseSerializationTestCase: BaseTestCase {
         XCTAssertNotNil(result.error, "result error should not be nil")
 
         if let error = result.error {
-            XCTAssertEqual(error.domain, Alamofire.Errors.Domain, "error domain should match expected value")
-            XCTAssertEqual(error.code, Alamofire.Errors.Code.propertyListSerializationFailed.rawValue, "error code should match expected value")
+            XCTAssertEqual(error.domain, ErrorDomain, "error domain should match expected value")
+            XCTAssertEqual(error.code, ErrorCode.propertyListSerializationFailed.rawValue, "error code should match expected value")
         } else {
             XCTFail("error should not be nil")
         }
@@ -488,8 +488,8 @@ class ResponseSerializationTestCase: BaseTestCase {
         XCTAssertNotNil(result.error, "result error should not be nil")
 
         if let error = result.error {
-            XCTAssertEqual(error.domain, Alamofire.Errors.Domain, "error domain should match expected value")
-            XCTAssertEqual(error.code, Alamofire.Errors.Code.propertyListSerializationFailed.rawValue, "error code should match expected value")
+            XCTAssertEqual(error.domain, ErrorDomain, "error domain should match expected value")
+            XCTAssertEqual(error.code, ErrorCode.propertyListSerializationFailed.rawValue, "error code should match expected value")
         } else {
             XCTFail("error should not be nil")
         }
@@ -543,7 +543,7 @@ class ResponseSerializationTestCase: BaseTestCase {
         XCTAssertNotNil(result.error, "result error should not be nil")
 
         if let error = result.error {
-            XCTAssertEqual(error.domain, Alamofire.Errors.Domain, "error domain should match expected value")
+            XCTAssertEqual(error.domain, ErrorDomain, "error domain should match expected value")
             XCTAssertEqual(error.code, self.error.code, "error code should match expected value")
         } else {
             XCTFail("error should not be nil")
@@ -565,8 +565,8 @@ class ResponseSerializationTestCase: BaseTestCase {
         XCTAssertNotNil(result.error, "result error should not be nil")
 
         if let error = result.error {
-            XCTAssertEqual(error.domain, Alamofire.Errors.Domain, "error domain should match expected value")
-            XCTAssertEqual(error.code, Alamofire.Errors.Code.propertyListSerializationFailed.rawValue, "error code should match expected value")
+            XCTAssertEqual(error.domain, ErrorDomain, "error domain should match expected value")
+            XCTAssertEqual(error.code, ErrorCode.propertyListSerializationFailed.rawValue, "error code should match expected value")
         } else {
             XCTFail("error should not be nil")
         }

+ 1 - 1
Tests/ResultTests.swift

@@ -27,7 +27,7 @@ import Foundation
 import XCTest
 
 class ResultTestCase: BaseTestCase {
-    let error = Alamofire.Errors.error(code: .statusCodeValidationFailed, failureReason: "Status code validation failed")
+    let error = NSError(code: .statusCodeValidationFailed, failureReason: "Status code validation failed")
 
     // MARK: - Is Success Tests
 

+ 24 - 24
Tests/ValidationTests.swift

@@ -69,9 +69,9 @@ class StatusCodeValidationTestCase: BaseTestCase {
         XCTAssertNotNil(error)
 
         if let error = error {
-            XCTAssertEqual(error.domain, Alamofire.Errors.Domain)
-            XCTAssertEqual(error.code, Alamofire.Errors.Code.statusCodeValidationFailed.rawValue)
-            XCTAssertEqual(error.userInfo[Alamofire.Errors.UserInfoKeys.StatusCode] as? Int, 404)
+            XCTAssertEqual(error.domain, ErrorDomain)
+            XCTAssertEqual(error.code, ErrorCode.statusCodeValidationFailed.rawValue)
+            XCTAssertEqual(error.userInfo[ErrorUserInfoKeys.StatusCode] as? Int, 404)
         } else {
             XCTFail("error should not be nil")
         }
@@ -98,9 +98,9 @@ class StatusCodeValidationTestCase: BaseTestCase {
         XCTAssertNotNil(error)
 
         if let error = error {
-            XCTAssertEqual(error.domain, Alamofire.Errors.Domain)
-            XCTAssertEqual(error.code, Alamofire.Errors.Code.statusCodeValidationFailed.rawValue)
-            XCTAssertEqual(error.userInfo[Alamofire.Errors.UserInfoKeys.StatusCode] as? Int, 201)
+            XCTAssertEqual(error.domain, ErrorDomain)
+            XCTAssertEqual(error.code, ErrorCode.statusCodeValidationFailed.rawValue)
+            XCTAssertEqual(error.userInfo[ErrorUserInfoKeys.StatusCode] as? Int, 201)
         } else {
             XCTFail("error should not be nil")
         }
@@ -177,9 +177,9 @@ class ContentTypeValidationTestCase: BaseTestCase {
         XCTAssertNotNil(error)
 
         if let error = error {
-            XCTAssertEqual(error.domain, Alamofire.Errors.Domain)
-            XCTAssertEqual(error.code, Alamofire.Errors.Code.contentTypeValidationFailed.rawValue)
-            XCTAssertEqual(error.userInfo[Alamofire.Errors.UserInfoKeys.ContentType] as? String, "application/xml")
+            XCTAssertEqual(error.domain, ErrorDomain)
+            XCTAssertEqual(error.code, ErrorCode.contentTypeValidationFailed.rawValue)
+            XCTAssertEqual(error.userInfo[ErrorUserInfoKeys.ContentType] as? String, "application/xml")
         } else {
             XCTFail("error should not be nil")
         }
@@ -206,9 +206,9 @@ class ContentTypeValidationTestCase: BaseTestCase {
         XCTAssertNotNil(error, "error should not be nil")
 
         if let error = error {
-            XCTAssertEqual(error.domain, Alamofire.Errors.Domain)
-            XCTAssertEqual(error.code, Alamofire.Errors.Code.contentTypeValidationFailed.rawValue)
-            XCTAssertEqual(error.userInfo[Alamofire.Errors.UserInfoKeys.ContentType] as? String, "application/xml")
+            XCTAssertEqual(error.domain, ErrorDomain)
+            XCTAssertEqual(error.code, ErrorCode.contentTypeValidationFailed.rawValue)
+            XCTAssertEqual(error.userInfo[ErrorUserInfoKeys.ContentType] as? String, "application/xml")
         } else {
             XCTFail("error should not be nil")
         }
@@ -361,9 +361,9 @@ class MultipleValidationTestCase: BaseTestCase {
         XCTAssertNotNil(error)
 
         if let error = error {
-            XCTAssertEqual(error.domain, Alamofire.Errors.Domain)
-            XCTAssertEqual(error.code, Alamofire.Errors.Code.statusCodeValidationFailed.rawValue)
-            XCTAssertEqual(error.userInfo[Alamofire.Errors.UserInfoKeys.StatusCode] as? Int, 200)
+            XCTAssertEqual(error.domain, ErrorDomain)
+            XCTAssertEqual(error.code, ErrorCode.statusCodeValidationFailed.rawValue)
+            XCTAssertEqual(error.userInfo[ErrorUserInfoKeys.StatusCode] as? Int, 200)
         } else {
             XCTFail("error should not be nil")
         }
@@ -391,9 +391,9 @@ class MultipleValidationTestCase: BaseTestCase {
         XCTAssertNotNil(error)
 
         if let error = error {
-            XCTAssertEqual(error.domain, Alamofire.Errors.Domain)
-            XCTAssertEqual(error.code, Alamofire.Errors.Code.contentTypeValidationFailed.rawValue)
-            XCTAssertEqual(error.userInfo[Alamofire.Errors.UserInfoKeys.ContentType] as? String, "application/xml")
+            XCTAssertEqual(error.domain, ErrorDomain)
+            XCTAssertEqual(error.code, ErrorCode.contentTypeValidationFailed.rawValue)
+            XCTAssertEqual(error.userInfo[ErrorUserInfoKeys.ContentType] as? String, "application/xml")
         } else {
             XCTFail("error should not be nil")
         }
@@ -448,9 +448,9 @@ class AutomaticValidationTestCase: BaseTestCase {
         XCTAssertNotNil(error)
 
         if let error = error {
-            XCTAssertEqual(error.domain, Alamofire.Errors.Domain)
-            XCTAssertEqual(error.code, Alamofire.Errors.Code.statusCodeValidationFailed.rawValue)
-            XCTAssertEqual(error.userInfo[Alamofire.Errors.UserInfoKeys.StatusCode] as? Int, 404)
+            XCTAssertEqual(error.domain, ErrorDomain)
+            XCTAssertEqual(error.code, ErrorCode.statusCodeValidationFailed.rawValue)
+            XCTAssertEqual(error.userInfo[ErrorUserInfoKeys.StatusCode] as? Int, 404)
         } else {
             XCTFail("error should not be nil")
         }
@@ -530,9 +530,9 @@ class AutomaticValidationTestCase: BaseTestCase {
         XCTAssertNotNil(error)
 
         if let error = error {
-            XCTAssertEqual(error.domain, Alamofire.Errors.Domain)
-            XCTAssertEqual(error.code, Alamofire.Errors.Code.contentTypeValidationFailed.rawValue)
-            XCTAssertEqual(error.userInfo[Alamofire.Errors.UserInfoKeys.ContentType] as? String, "application/xml")
+            XCTAssertEqual(error.domain, ErrorDomain)
+            XCTAssertEqual(error.code, ErrorCode.contentTypeValidationFailed.rawValue)
+            XCTAssertEqual(error.userInfo[ErrorUserInfoKeys.ContentType] as? String, "application/xml")
         } else {
             XCTFail("error should not be nil")
         }