From 45b864b00d28713c49f98fd08496e82e1e679c43 Mon Sep 17 00:00:00 2001 From: Andrei Freeman Date: Wed, 29 Jun 2016 12:13:27 -0400 Subject: [PATCH] Uses local error domain and local error generation function --- .../AlamofireObjectMapper.swift | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/AlamofireObjectMapper/AlamofireObjectMapper.swift b/AlamofireObjectMapper/AlamofireObjectMapper.swift index 6318785..f37eb0f 100644 --- a/AlamofireObjectMapper/AlamofireObjectMapper.swift +++ b/AlamofireObjectMapper/AlamofireObjectMapper.swift @@ -32,6 +32,15 @@ import ObjectMapper extension Request { + internal static func newError(code: Error.Code, failureReason: String) -> NSError { + let errorDomain = "com.alamofireobjectmapper.error" + + let userInfo = [NSLocalizedFailureReasonErrorKey: failureReason] + let returnError = NSError(domain: errorDomain, code: code.rawValue, userInfo: userInfo) + + return returnError + } + public static func ObjectMapperSerializer(keyPath: String?, mapToObject object: T? = nil, context: MapContext? = nil) -> ResponseSerializer { return ResponseSerializer { request, response, data, error in guard error == nil else { @@ -40,7 +49,7 @@ extension Request { guard let _ = data else { let failureReason = "Data could not be serialized. Input data was nil." - let error = Error.errorWithCode(.DataSerializationFailed, failureReason: failureReason) + let error = newError(.DataSerializationFailed, failureReason: failureReason) return .Failure(error) } @@ -62,7 +71,7 @@ extension Request { } let failureReason = "ObjectMapper failed to serialize response." - let error = Error.errorWithCode(.DataSerializationFailed, failureReason: failureReason) + let error = newError(.DataSerializationFailed, failureReason: failureReason) return .Failure(error) } } @@ -90,7 +99,7 @@ extension Request { guard let _ = data else { let failureReason = "Data could not be serialized. Input data was nil." - let error = Error.errorWithCode(.DataSerializationFailed, failureReason: failureReason) + let error = newError(.DataSerializationFailed, failureReason: failureReason) return .Failure(error) } @@ -109,7 +118,7 @@ extension Request { } let failureReason = "ObjectMapper failed to serialize response." - let error = Error.errorWithCode(.DataSerializationFailed, failureReason: failureReason) + let error = newError(.DataSerializationFailed, failureReason: failureReason) return .Failure(error) } }