cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Download Error, how to extract info

Download Error, how to extract info

David E.64
New member | Level 1

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 2

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.64
New member | Level 1

thanks Gregory, i'll give that a bash 👍 

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    David E.64 New member | Level 1
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?