mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-17 21:25:06 +02:00
* Add try & catch in the case of a 504 error being generated to upload the file. Currently, if a 504 is generated, it is handled gracefully, but further files to upload are stopped * Update where ever there is a 404 try block, add a if statement to capture if a 5xx error is returned as well
This commit is contained in:
parent
3a4c71d7ee
commit
a6336e70b3
|
@ -252,6 +252,11 @@ int main(string[] args)
|
||||||
onedrive.http.shutdown();
|
onedrive.http.shutdown();
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
if (e.httpStatusCode >= 500) {
|
||||||
|
// There was a HTTP 5xx Server Side Error, message already printed
|
||||||
|
onedrive.http.shutdown();
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We should only set noRemoteDelete in an upload-only scenario
|
// We should only set noRemoteDelete in an upload-only scenario
|
||||||
|
|
77
src/sync.d
77
src/sync.d
|
@ -168,7 +168,12 @@ final class SyncEngine
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
// Set accountType, defaultDriveId, defaultRootId & remainingFreeSpace once and reuse where possible
|
// Set accountType, defaultDriveId, defaultRootId & remainingFreeSpace once and reuse where possible
|
||||||
auto oneDriveDetails = onedrive.getDefaultDrive();
|
JSONValue oneDriveDetails;
|
||||||
|
|
||||||
|
// Need to catch 5xx server side errors at initialization
|
||||||
|
try {
|
||||||
|
oneDriveDetails = onedrive.getDefaultDrive();
|
||||||
|
// Successfully got details from OneDrive without a server side error such as HTTP/1.1 504 Gateway Timeout
|
||||||
accountType = oneDriveDetails["driveType"].str;
|
accountType = oneDriveDetails["driveType"].str;
|
||||||
defaultDriveId = oneDriveDetails["id"].str;
|
defaultDriveId = oneDriveDetails["id"].str;
|
||||||
defaultRootId = onedrive.getDefaultRoot["id"].str;
|
defaultRootId = onedrive.getDefaultRoot["id"].str;
|
||||||
|
@ -183,12 +188,18 @@ final class SyncEngine
|
||||||
// Check the local database to ensure the OneDrive Root details are in the database
|
// Check the local database to ensure the OneDrive Root details are in the database
|
||||||
checkDatabaseForOneDriveRoot();
|
checkDatabaseForOneDriveRoot();
|
||||||
|
|
||||||
// check if there is an interrupted upload session
|
// Check if there is an interrupted upload session
|
||||||
if (session.restore()) {
|
if (session.restore()) {
|
||||||
log.log("Continuing the upload session ...");
|
log.log("Continuing the upload session ...");
|
||||||
auto item = session.upload();
|
auto item = session.upload();
|
||||||
saveItem(item);
|
saveItem(item);
|
||||||
}
|
}
|
||||||
|
} catch (OneDriveException e) {
|
||||||
|
if (e.httpStatusCode >= 500) {
|
||||||
|
// There was a HTTP 5xx Server Side Error
|
||||||
|
log.error("ERROR: OneDrive returned a 'HTTP 5xx Server Side Error' - Cannot Initialize Sync Engine");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure noRemoteDelete if function is called
|
// Configure noRemoteDelete if function is called
|
||||||
|
@ -226,6 +237,11 @@ final class SyncEngine
|
||||||
log.error("ERROR: The requested single directory to sync was not found on OneDrive");
|
log.error("ERROR: The requested single directory to sync was not found on OneDrive");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (e.httpStatusCode >= 500) {
|
||||||
|
// OneDrive returned a 'HTTP 5xx Server Side Error' - gracefully handling error - error message already logged
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// OK - the path on OneDrive should exist, get the driveId and rootId for this folder
|
// OK - the path on OneDrive should exist, get the driveId and rootId for this folder
|
||||||
log.vlog("Getting path details from OneDrive ...");
|
log.vlog("Getting path details from OneDrive ...");
|
||||||
|
@ -290,6 +306,11 @@ final class SyncEngine
|
||||||
log.vlog("The requested directory to delete was not found on OneDrive - skipping removing the remote directory as it doesn't exist");
|
log.vlog("The requested directory to delete was not found on OneDrive - skipping removing the remote directory as it doesn't exist");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (e.httpStatusCode >= 500) {
|
||||||
|
// OneDrive returned a 'HTTP 5xx Server Side Error' - gracefully handling error - error message already logged
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Item item;
|
Item item;
|
||||||
|
@ -317,6 +338,11 @@ final class SyncEngine
|
||||||
log.vlog("The requested directory to rename was not found on OneDrive");
|
log.vlog("The requested directory to rename was not found on OneDrive");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (e.httpStatusCode >= 500) {
|
||||||
|
// OneDrive returned a 'HTTP 5xx Server Side Error' - gracefully handling error - error message already logged
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// The OneDrive API returned a 200 OK status, so the folder exists
|
// The OneDrive API returned a 200 OK status, so the folder exists
|
||||||
// Rename the requested directory on OneDrive without performing a sync
|
// Rename the requested directory on OneDrive without performing a sync
|
||||||
|
@ -342,6 +368,11 @@ final class SyncEngine
|
||||||
log.vlog("No details returned for given Path ID");
|
log.vlog("No details returned for given Path ID");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (e.httpStatusCode >= 500) {
|
||||||
|
// OneDrive returned a 'HTTP 5xx Server Side Error' - gracefully handling error - error message already logged
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the name of this 'Path ID'
|
// Get the name of this 'Path ID'
|
||||||
|
@ -456,6 +487,11 @@ final class SyncEngine
|
||||||
log.vlog("Remote change discarded - item cannot be found");
|
log.vlog("Remote change discarded - item cannot be found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (e.httpStatusCode >= 500) {
|
||||||
|
// OneDrive returned a 'HTTP 5xx Server Side Error' - gracefully handling error - error message already logged
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Yes .. ID is still on OneDrive but elsewhere .... #341 edge case handling
|
// Yes .. ID is still on OneDrive but elsewhere .... #341 edge case handling
|
||||||
// What is the original local path for this ID in the database? Does it match 'syncFolderName'
|
// What is the original local path for this ID in the database? Does it match 'syncFolderName'
|
||||||
|
@ -1105,6 +1141,11 @@ final class SyncEngine
|
||||||
// Parent does not exist ... need to create parent
|
// Parent does not exist ... need to create parent
|
||||||
uploadCreateDir(parentPath);
|
uploadCreateDir(parentPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (e.httpStatusCode >= 500) {
|
||||||
|
// OneDrive returned a 'HTTP 5xx Server Side Error' - gracefully handling error - error message already logged
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// configure the data
|
// configure the data
|
||||||
|
@ -1145,6 +1186,11 @@ final class SyncEngine
|
||||||
log.vlog("Successfully created the remote directory ", path, " on OneDrive");
|
log.vlog("Successfully created the remote directory ", path, " on OneDrive");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (e.httpStatusCode >= 500) {
|
||||||
|
// OneDrive returned a 'HTTP 5xx Server Side Error' - gracefully handling error - error message already logged
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file
|
// https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file
|
||||||
|
@ -1219,8 +1265,14 @@ final class SyncEngine
|
||||||
if (thisFileSize == 0){
|
if (thisFileSize == 0){
|
||||||
// We can only upload zero size files via simpleFileUpload regardless of account type
|
// We can only upload zero size files via simpleFileUpload regardless of account type
|
||||||
// https://github.com/OneDrive/onedrive-api-docs/issues/53
|
// https://github.com/OneDrive/onedrive-api-docs/issues/53
|
||||||
|
try {
|
||||||
response = onedrive.simpleUpload(path, parent.driveId, parent.id, baseName(path));
|
response = onedrive.simpleUpload(path, parent.driveId, parent.id, baseName(path));
|
||||||
writeln(" done.");
|
writeln(" done.");
|
||||||
|
} catch (OneDriveException e) {
|
||||||
|
// error uploading file
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// File is not a zero byte file
|
// File is not a zero byte file
|
||||||
// Are we using OneDrive Personal or OneDrive Business?
|
// Are we using OneDrive Personal or OneDrive Business?
|
||||||
|
@ -1235,21 +1287,37 @@ final class SyncEngine
|
||||||
if (e.httpStatusCode == 504) {
|
if (e.httpStatusCode == 504) {
|
||||||
// HTTP request returned status code 504 (Gateway Timeout)
|
// HTTP request returned status code 504 (Gateway Timeout)
|
||||||
// Try upload as a session
|
// Try upload as a session
|
||||||
|
try {
|
||||||
response = session.upload(path, parent.driveId, parent.id, baseName(path));
|
response = session.upload(path, parent.driveId, parent.id, baseName(path));
|
||||||
|
} catch (OneDriveException e) {
|
||||||
|
// error uploading file
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else throw e;
|
else throw e;
|
||||||
}
|
}
|
||||||
writeln(" done.");
|
writeln(" done.");
|
||||||
} else {
|
} else {
|
||||||
|
// File larger than threshold - use a session to upload
|
||||||
writeln("");
|
writeln("");
|
||||||
|
try {
|
||||||
response = session.upload(path, parent.driveId, parent.id, baseName(path));
|
response = session.upload(path, parent.driveId, parent.id, baseName(path));
|
||||||
writeln(" done.");
|
writeln(" done.");
|
||||||
|
} catch (OneDriveException e) {
|
||||||
|
// error uploading file
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// OneDrive Business Account - always use a session to upload
|
// OneDrive Business Account - always use a session to upload
|
||||||
writeln("");
|
writeln("");
|
||||||
|
try {
|
||||||
response = session.upload(path, parent.driveId, parent.id, baseName(path));
|
response = session.upload(path, parent.driveId, parent.id, baseName(path));
|
||||||
writeln(" done.");
|
writeln(" done.");
|
||||||
|
} catch (OneDriveException e) {
|
||||||
|
// error uploading file
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1288,6 +1356,11 @@ final class SyncEngine
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (e.httpStatusCode >= 500) {
|
||||||
|
// OneDrive returned a 'HTTP 5xx Server Side Error' - gracefully handling error - error message already logged
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that the filename that is returned is actually the file we wish to upload
|
// Check that the filename that is returned is actually the file we wish to upload
|
||||||
|
|
Loading…
Reference in a new issue