dropbox-sdk-js
dropbox-sdk-js copied to clipboard
What does error message "Failed to fetch" mean?
Every single day I get Failed to fetch generic error message when using the upload files v2 api.
What do I benefit from such generic message?
I cannot even debug the issue or know what's wrong, It happens so randomly from time to time!!!

We'll be happy to help with any issues you're having with the Dropbox API/SDK, but we'll need some more information. Can you please share:
- the name and version number of the platform where you're running this
- the version number of the Dropbox JavaScript SDK you're using
- the steps to reproduce the issue, including relevant code snippet(s)
I also rarely get the error message Failed to fetch in our logs as the only response from a call to filesListFolder. (^5.2.1 on web, Chrome) I dont know what status code it returns though. Might also be a console.error(). No idea whats going on or how to handle this. I should probably upgrade though.
@phil294 We haven't heard back from the original poster here, and we don't know exactly what the cause of this is. If you can share some way for us to reproduce it though, we'll look into it. In any case, we do recommend upgrading to the latest version of the SDK.
I actually just now found the reason in my case: When the site is offline, a call like x = await filesListFolder(...) fails with a simple
message: "Failed to fetch",
stack: "TypeError: Failed to fetch"
object. This is also the case with v8.2.0. I'll now just do a try { ... } catch(e) { if(e.message === 'Failed to fetch') { /* show network error to the user */ } }. Thanks for your help and I hope this will help someone else.
@greg-db I'm not sure how can I re-produce the error because I cannot myself, I have pretty much this setup on my App and the error is totally random, I just don't know what the error is or where it happen.
But as @phil294 mentioned my App is fully PWA (https://app.replayed.co), and I always show network error to the user. In my case the error is happen after couple fetches so it's not like there's connection at all or the user access the page immediately from offline. It happens like 50% of the time, It's getting annoying. I'm not sure what to do!
@ImSolitude Thanks for following up. Unfortunately if we can't reproduce the issue here, it's unlikely we'll be able to offer much help.
To clarify though, since your app is a PWA, it seems the API calls are made client-side on your users' devices (and you're just seeing the error report). Is that correct? Given that you can't reproduce it yourself, and since Philip mentioned this can happen when offline, it may indicate that it happens when the user has even just an unreliable connection, if not completely offline.
Hey @greg-db, An update to this, We checked the sentry issues and it was filled with this error,
TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation, We're using dropbox: 8.1.0, and we're not passing any custom fetcher to the Dropbox constructor.
const dbx = new Dropbox({
clientId: `${process.env.REACT_APP_DROPBOX_CLIENT_ID}`,
accessToken: `${process.env.REACT_APP_DROPBOX_ACCESS_TOKEN}`,
pathRoot: '{".tag": "namespace_id", "namespace_id": "####"}',
selectUser: `${process.env.REACT_APP_DROPBOX_SELECT_USER}`,
});
Not sure what's wrong.

@ImSolitude Thanks for the information. From that code, it looks like you're using this in a React app. This SDK doesn't officially support React unfortunately, but I'll pass this along as a feature request. I can't promise if or when that might be implemented though.
Hi,
I have same fetch error problem. I have a node.js app which runs on AWS Lambda. The Lambda is connected with a VPC. It goes internet with a static IP. I use v10.23.0 dropbox-sdk-js. It always seems to run on my local but It sometimes runs on lambda, sometimes gets fetch error.
My code like this:
async function main() {
const Dropbox = require('dropbox').Dropbox;
const dropbox = {
dbx: new Dropbox({
accessToken: process.env.ACCESS_TOKEN,
pathRoot: JSON.stringify({ '.tag': 'namespace_id', 'namespace_id': process.env.NAMESPACE_ID })
})
};
const payload = {
path: '',
recursive: true,
include_media_info: false,
include_deleted: false,
include_has_explicit_shared_members: true,
include_mounted_folders: true,
include_non_downloadable_files: true
};
let hasMore = true;
let entries = [];
let response;
let cursor;
while (hasMore) {
try {
if (cursor) {
response = await dropbox.dbx.filesListFolderContinue({ cursor: cursor });
}
else {
response = await dropbox.dbx.filesListFolderGetLatestCursor(payload);
response = await dropbox.dbx.filesListFolderContinue({ cursor: response.result.cursor });
}
console.info('Entries: ', JSON.stringify(response.result.entries));
cursor = response.result.cursor;
entries = entries.concat(response.result.entries);
hasMore = response.result.has_more;
}
catch (error) {
console.info(error);
return error;
}
}
}
main();
Error log:
2022-01-20T08:22:18.579Z 67caa239-e75c-46ce-be4c-0fcf6c154694 INFO FetchError: request to https://api.dropboxapi.com/2/files/list_folder/continue failed, reason: connect ETIMEDOUT 162.125.4.19:443
at ClientRequest.<anonymous> (/var/task/node_modules/dropbox/node_modules/node-fetch/lib/index.js:1483:11)
at ClientRequest.emit (events.js:400:28)
at TLSSocket.socketErrorListener (_http_client.js:475:9)
at TLSSocket.emit (events.js:400:28)
at emitErrorNT (internal/streams/destroy.js:106:8)
at emitErrorCloseNT (internal/streams/destroy.js:74:3)
at processTicksAndRejections (internal/process/task_queues.js:82:21) {
type: 'system',
errno: 'ETIMEDOUT',
code: 'ETIMEDOUT'
}
@ridvankartal It looks like you're not getting the exact same error as originally reported in this thread. The original reports were about a generic "Failed to fetch" error, but you're getting an "ETIMEDOUT" error. Anyway, I'll reply on your forum thread. By the way, for future reference, it is not necessary to post the same issue in multiple places.