We are aware of the issue with the badge emails resending to everyone, we apologise for the inconvenience - learn more here.

Forum Discussion

jimbobbles's avatar
jimbobbles
Explorer | Level 3
4 months ago

Figuring out what type of error in unboxed in SwiftyDropbox

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!

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox 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's avatar
      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!

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,877 PostsLatest Activity: 12 months ago
325 Following

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!