Take Your Search Game to the Next Level with Dropbox Dash 🚀✨ Curious how it works? Ask us here!
Forum Discussion
David E.64
9 years agoNew member | Level 1
Download Error, how to extract info
Hi,
I am brand new to Swift, in fact only started looking at it in order to use swiftydropbox! Currently I don't see how to extract info from the downloadError without doing string finding jiggery pokkery!
I am coming from objC class and sending a download with completion message to my swift wrapper class which contains client.files.download()
if there is no response I am doing this:
completion(success: false, error: error?.description)
however I am finding it tricky to use this error description back in my objC class. What is best way to simply get the error code out of this or the NSUnderlyingError? I feel sure I don't need to go wading into that string and searching for key phrases?
Thanks and sorry for the noob question!
2 Replies
Sort By
- Greg-DB
Dropbox Staff
Hi David, here's an example of using files.download with every error case handled in Swift: (apologies for the poor formatting on the forum)
Dropbox.authorizedClient!.files.download(path: path, destination: destination).response { response, error in
if let (metadata, url) = response {
print("*** Download file ***")
print("Downloaded file name: \(metadata.name)")
print("Downloaded file url: \(url)")
} else if let callError = error {
switch callError as CallError {
case .RouteError(let boxed, let requestId):
print("RouteError[\(requestId)]:")
switch boxed.unboxed as Files.DownloadError {
case .Path(let fileLookupError):
print("PathError: ")
switch fileLookupError {
case .MalformedPath(let malformedPathError):
print("MalformedPath: \(malformedPathError)")
case .NotFile:
print("NotFile")
case .NotFolder:
print("NotFolder")
case .NotFound:
print("NotFound")
case .RestrictedContent:
print("RestrictedContent")
case .Other:
print("Other")
}
case .Other:
print("Other")
}
case .BadInputError(let message, let requestId):
print("BadInputError[\(requestId)]: \(message)")
case .HTTPError(let code, let message, let requestId):
print("HTTPError[\(requestId)]: \(code): \(message)")
case .InternalServerError(let code, let message, let requestId):
print("InternalServerError[\(requestId)]: \(code): \(message)")
case .OSError(let err):
print("OSError: \(err)")
case .RateLimitError:
print("RateLimitError")
}
}
}If I understand your question correctly, you can do the specific error detection in your Swift code, and then send whatever indicator or information you want back to the Objective-C side, as opposed to the error object or description itself.
- David E.64New member | Level 1
thanks Gregory, i'll give that a bash 👍
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,988 PostsLatest Activity: 6 hours ago
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!