提交 b87fb428 编写于 作者: C Christian Noon

Modified error handling to use implicit error catching to avoid fatal errors.

上级 14d1d716
......@@ -156,8 +156,8 @@ extension Request {
do {
let destination = downloadTaskDidFinishDownloadingToURL!(session, downloadTask, location)
try NSFileManager.defaultManager().moveItemAtURL(location, toURL: destination)
} catch let moveError as NSError {
self.error = moveError
} catch {
self.error = error as NSError
}
}
}
......
......@@ -79,7 +79,7 @@ public enum ParameterEncoding {
}
var mutableURLRequest: NSMutableURLRequest! = URLRequest.URLRequest.mutableCopy() as! NSMutableURLRequest
var error: NSError? = nil
var encodingError: NSError? = nil
switch self {
case .URL:
......@@ -121,22 +121,22 @@ public enum ParameterEncoding {
let data = try NSJSONSerialization.dataWithJSONObject(parameters!, options: options)
mutableURLRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
mutableURLRequest.HTTPBody = data
} catch let serializationError as NSError {
error = serializationError
} catch {
encodingError = error as NSError
}
case .PropertyList(let (format, options)):
do {
let data = try NSPropertyListSerialization.dataWithPropertyList(parameters!, format: format, options: options)
mutableURLRequest.setValue("application/x-plist", forHTTPHeaderField: "Content-Type")
mutableURLRequest.HTTPBody = data
} catch let serializationError as NSError {
error = serializationError
} catch {
encodingError = error as NSError
}
case .Custom(let closure):
return closure(mutableURLRequest, parameters)
}
return (mutableURLRequest, error)
return (mutableURLRequest, encodingError)
}
func queryComponents(key: String, _ value: AnyObject) -> [(String, String)] {
......
......@@ -81,16 +81,13 @@ extension Request {
return (nil, nil)
}
let JSON: AnyObject?
var JSON: AnyObject?
var serializationError: NSError?
do {
JSON = try NSJSONSerialization.JSONObjectWithData(data!, options: options)
} catch let error as NSError {
serializationError = error
JSON = nil
} catch {
fatalError("JSON serialization failed and did not return an error")
serializationError = error as NSError
}
return (JSON, serializationError)
......@@ -128,16 +125,13 @@ extension Request {
return (nil, nil)
}
let plist: AnyObject?
var plist: AnyObject?
var propertyListSerializationError: NSError?
do {
plist = try NSPropertyListSerialization.propertyListWithData(data!, options: options, format: nil)
} catch let error as NSError {
propertyListSerializationError = error
plist = nil
} catch {
fatalError("Property list serialization failed and did not return an error")
propertyListSerializationError = error as NSError
}
return (plist, propertyListSerializationError)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册