         return parameters
     }
     
+    func checkForApiResultError(resultDict:NSDictionary) -> NSError? {
+        var error:NSError? = nil
+        if let errorDict = resultDict["error"] as? NSDictionary {
+            var userInfo = [String : AnyObject]()
+            if let code = errorDict["code"] as? String {
+                userInfo.updateValue(code, forKey: NSLocalizedFailureReasonErrorKey)
+            }
+            if let message = errorDict["message"] as? String {
+                userInfo.updateValue(message, forKey: NSLocalizedDescriptionKey)
+            }
+            error = NSError(domain: "com.technomagination.EasyPostApi", code: 1, userInfo: userInfo)
+        }
+        return error
+    }
+    
     //Post and address model and get an address object with id populated back
     public func postAddress(address:EasyPostAddress, completion: (result: EasyPostResult<EasyPostAddress>) -> ()) {
         

import Alamofire

public class EasyPostApi {
    
    var apiToken = ""               //Pass in via setCredentials
    var apiBaseUrl = ""             //Pass in via setCredentials

                if(result.isSuccess) {
                    
                    if let resultDict = result.value as? NSDictionary {
                        if let error = self.checkForApiResultError(resultDict) {
                            completion(result: EasyPostResult.Failure(error))
                        } else {
                            if let addressDict = resultDict["address"] as? NSDictionary {
                                let address = EasyPostAddress(jsonDictionary: addressDict)
                            
                                completion(result: EasyPostResult.Success(address))
                            } else {
                                let userInfo = [NSLocalizedDescriptionKey : "address element was not found in results"]
                                completion(result: EasyPostResult.Failure(NSError(domain: self.errorDomain, code: 2, userInfo: userInfo)))
                            }
                        }
                    } else {
                        print("Result was successful, but blank.")
                        completion(result: EasyPostResult.Failure(NSError(domain: self.errorDomain, code: 2, userInfo: nil)))
                    }
                    
                    
