cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Are you an educator? Well we want to hear from you, so check out some tools we think might help you out 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: 

Checking for a single error condition

Checking for a single error condition

chiisai
New member | Level 2

Hi,

 

I am creating a function that can be used to download either a single file, or recursively download an entire folder.  To accomplish this, I am calling listFolder but since this may return an error if the folder is instead a file, I would like to check for that single error case.  What I have so far is this:

 

        dbInfoJob = client.files.listFolder(path: path, recursive: true).response { response, error in
            //let error: CallError<Files.ListFolderError>?
            if error != nil {
                var realError = true
                switch error! {
                case .routeError(let boxed, _, _, _):
                    switch boxed.unboxed {
                    case .path(let lookupError):
                        print("Path Error: \(lookupError)")
                        switch lookupError as Files.LookupError {
                        case .notFolder:
                            // NOTE: this is okay... we are only working with a single file.  any other error is a problem
                            realError = false
                         default: break
                        }
                    default: break
                    }
                default: break
                    
                }
                if realError {
                    // TODO: handle this real error case
                }
         }
    }

How can this be written as an if statement so that I don't have to have all of these "default: break" in a switch statement?

 

Thanks!

 

1 Reply 1

Re: Checking for a single error condition

Greg-DB
Dropboxer
I don't believe there's a good shorter way to do this.

You could potentially parse out the error from `description` but I don't recommend doing so.
Poll
We love to learn from the educators who use Dropbox. Whether you teach kids, teens, adults or a combination of all three, we want to know what apps and integrations you use with Dropbox to help with teaching. Which of the ones below is your favorite, or most used tool?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropboxer
What do Dropbox user levels mean?
Need more support?