mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-20 14:46:35 +02:00
Update 'HTTP 412 - Precondition Failed' error handling (#67)
* Update 'HTTP 412 - Precondition Failed' error handling based on local testing to ensure a http 412 response is gracefully handled & the modified file is subsequently uploaded to OneDrive successfully.
This commit is contained in:
parent
54ae6eacad
commit
a4e055fdc3
|
@ -540,8 +540,12 @@ final class OneDriveApi
|
||||||
|
|
||||||
private void checkHttpCode(ref const JSONValue response)
|
private void checkHttpCode(ref const JSONValue response)
|
||||||
{
|
{
|
||||||
if (http.statusLine.code / 100 != 2) {
|
if (http.statusLine.code == 412) {
|
||||||
throw new OneDriveException(http.statusLine.code, http.statusLine.reason, response);
|
throw new OneDriveException(http.statusLine.code, http.statusLine.reason);
|
||||||
|
} else {
|
||||||
|
if (http.statusLine.code / 100 != 2) {
|
||||||
|
throw new OneDriveException(http.statusLine.code, http.statusLine.reason, response);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
26
src/sync.d
26
src/sync.d
|
@ -824,7 +824,7 @@ final class SyncEngine
|
||||||
string eTag = item.eTag;
|
string eTag = item.eTag;
|
||||||
if (!testFileHash(path, item)) {
|
if (!testFileHash(path, item)) {
|
||||||
log.vlog("The file content has changed");
|
log.vlog("The file content has changed");
|
||||||
write("Uploading file ", path, " ...");
|
write("Uploading file ", path, " ... ");
|
||||||
JSONValue response;
|
JSONValue response;
|
||||||
|
|
||||||
// Are we using OneDrive Personal or OneDrive Business?
|
// Are we using OneDrive Personal or OneDrive Business?
|
||||||
|
@ -846,20 +846,28 @@ final class SyncEngine
|
||||||
log.fileOnly(path, " is currently checked out or locked for editing by another user.");
|
log.fileOnly(path, " is currently checked out or locked for editing by another user.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (e.httpStatusCode == 412) {
|
||||||
|
// HTTP request returned status code 412 - ETag does not match current item's value
|
||||||
|
// Remove the offending file from OneDrive - file will be uploaded as a new file
|
||||||
|
onedrive.deleteById(item.driveId, item.id, item.eTag);
|
||||||
|
// Delete from the local database
|
||||||
|
itemdb.deleteById(item.driveId, item.id);
|
||||||
|
}
|
||||||
|
|
||||||
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
|
||||||
response = session.upload(path, item.driveId, item.parentId, baseName(path), eTag);
|
response = session.upload(path, item.driveId, item.parentId, baseName(path), item.eTag);
|
||||||
}
|
}
|
||||||
else throw e;
|
else throw e;
|
||||||
}
|
}
|
||||||
writeln(" done.");
|
writeln("done.");
|
||||||
} else {
|
} else {
|
||||||
writeln("");
|
writeln("");
|
||||||
response = session.upload(path, item.driveId, item.parentId, baseName(path), eTag);
|
response = session.upload(path, item.driveId, item.parentId, baseName(path), item.eTag);
|
||||||
writeln(" done.");
|
writeln("done.");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// OneDrive Business Account - always use a session to upload
|
// OneDrive Business Account - always use a session to upload
|
||||||
writeln("");
|
writeln("");
|
||||||
|
@ -880,12 +888,12 @@ final class SyncEngine
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
writeln(" done.");
|
writeln("done.");
|
||||||
// As the session.upload includes the last modified time, save the response
|
// As the session.upload includes the last modified time, save the response
|
||||||
saveItem(response);
|
saveItem(response);
|
||||||
}
|
}
|
||||||
log.fileOnly("Uploading file ", path, " ... done.");
|
log.fileOnly("Uploading file ", path, " ... done.");
|
||||||
// use the cTag instead of the eTag because Onedrive may update the metadata of files AFTER they have been uploaded
|
// use the cTag instead of the eTag because OneDrive may update the metadata of files AFTER they have been uploaded
|
||||||
eTag = response["cTag"].str;
|
eTag = response["cTag"].str;
|
||||||
}
|
}
|
||||||
if (accountType == "personal"){
|
if (accountType == "personal"){
|
||||||
|
|
Loading…
Reference in a new issue