cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
We are making some updates so the Community might be down for a few hours on Monday the 11th of November. Apologies for the inconvenience and thank you for your patience. You can find out more 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: 

Figuring out what type of error in unboxed in SwiftyDropbox

Figuring out what type of error in unboxed in SwiftyDropbox

jimbobbles
Explorer | Level 3

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!

3 Replies 3

Greg-DB
Dropbox Staff

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 a Void 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 a Files.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.

jimbobbles
Explorer | Level 3

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:

  • notFound
  • incorrectOffset(_:)
  • closed
  • notClosed
  • tooLarge
  • concurrentSessionInvalidOffset
  • concurrentSessionInvalidDataSize
  • payloadTooLarge
  • other
  • contentHashMismatch

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!

Greg-DB
Dropbox Staff

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.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    jimbobbles Explorer | Level 3
What do Dropbox user levels mean?