Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
I'm trying to understand how to catch and parse errors from the swifty dropbox SDK, specifically route errors. Apologies if this is a simple question, I'm new to Swift!
In the examples that I've seen (for example here), a route error is unboxed and then cast to a specific error type like this:
case .routeError(let boxed, let requestId, nil, nil):
switch boxed.unboxed as Files.ListFolderError {
case .path(let lookupError):
...
What I'm struggling to understand is how do you know what type boxed.unboxed should be (in this case it was files.ListFolderError)?
For example, for the uploadSessionStartBatch route, I have the following code - what kind of route error does uploadSessionStartBatch return? How do I find this out? I'm trying to cast it to a type which I can parse to detect if the user is out of space.
do {
let uploadSessionStartBatchResult = try await client.files.uploadSessionStartBatch(
numSessions: UInt64(filePaths.count), sessionType: .concurrent).response()
}
catch {
switch error as? CallError<Any> {
case .routeError(let error, let userMessage, let errorSummary, let requestId):
switch error.unboxed as Files.???? {
// e.g. catch insufficient space error
}
}
}
Thanks so much!
The uploadSessionStartBatch method doesn't actually have a route specific error type, because it doesn't have any route specific errors. (It's just Void.) You can see this in the uploadSessionStartBatch documentation where it says:
Return Value
Through the response callback, the caller will receive a
Files.UploadSessionStartBatchResult
object on success or aVoid
object on failure.
For comparison, you can see how the listFolder documentation says:
Return Value
Through the response callback, the caller will receive a
Files.ListFolderResult
object on success or aFiles.ListFolderError
object on failure.
The uploadSessionStartBatch method itself doesn't upload or commit any data, and so doesn't consume any space in the user's account; that means it can't cause the user's account to go over quota and so can't trigger any over quota error for you to catch.
If you want to proactively check the user's space usage though, you can call getSpaceUsage.
Ah right, thank you. It looks like uploadSessionFinishBatchV2 also returns Void, which is surpirising because the Java version of uploadSessionFinishBatchV2 returns a WriteError.INSUFFICIENT_SPACE if there isn't enough space. Furthermore, uploadSessionAppendV2 returns an UploadSessionAppendError which has the following values:
I don't see an insufficient space value, so I'm still not sure how to catch an insufficient space error during batch upload - any pointers would be highly appreciated. I'd rather not have to proactively check before each upload (I'm not sure how you could safely do that when uploading many files in parallel)
Thanks!
The Java SDK isn't inconsistent with the Swift SDK; it doesn't directly return a WriteError. The Java SDK uploadSessionFinishBatchV2 method returns UploadSessionFinishBatchResult which has an entries field which is a list of UploadSessionFinishBatchResultEntry each of which might be a failure, and if it is a failure it would be a UploadSessionFinishError, and in some cases might be a WriteError in particular. Check out the linked documentation for more information on how to check the types at check step of that process.
You would do the same in the Swift SDK. The UploadSessionFinishBatchResult has entries which is a list of UploadSessionFinishBatchResultEntry, each of which is success or failure, and if it's a failure the object indicates why it failed, and so on.
Hi there!
If you need more help you can view your support options (expected response time for a 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!