0

Im creating the following process:

  1. Upload a file to dropbox using the API
  2. After upload, create a shared link for that file
  3. If a shared link already exists, get that existing shared link for the user

My Issue:

Im using the following code to check if the shared link already exists:

if(x.error[".tag"] === "shared_link_already_exists"){
  //code to get existing shared link here
}

When I upload a new file which has never had a shared link created I get the following error:

TypeError: Cannot read property '.tag' of undefined

How can I get around this?

1
  • why don't you check whether error exists and then .tag inside as follows !!x.error && x.error[".tag"] === "shared_link_already_exists"]
    – kgangadhar
    Commented Oct 1, 2017 at 16:15

1 Answer 1

2

If you get the shared_link_already_exists error when calling /2/sharing/create_shared_link_with_settings, you can retrieve the existing link by calling /2/sharing/list_shared_links with path set to the path of the file/folder for which you want a link, and direct_only=true.

And kgangadhar's comment is correct, you should check if there is an error before attempting to access '.tag' on it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.