Last active
September 28, 2016 06:44
-
-
Save fernandomatal/604aec1a202e5261ce0b3c4a878c42a5 to your computer and use it in GitHub Desktop.
An extension to get serialized error data when server sends some data on the error response.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension NSError { | |
var serializedErrorData: [String : AnyObject]? { | |
get { | |
if let responseData = userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey] as? NSData { | |
if let data = try? NSJSONSerialization.JSONObjectWithData(responseData, options: NSJSONReadingOptions.AllowFragments) as? [String : AnyObject] { | |
return data | |
} | |
} | |
return nil | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment