mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-19 22:25:03 +02:00
Update sync.d (#329)
* Update HTTP 412 error notifications to better identify where 412 error is occuring * Add a check for 'id' key on metadata update to prevent 'std.json.JSONException@std/json.d(494): Key not found: id' (Issue #325)
This commit is contained in:
parent
46ef8ed376
commit
ddc5d602da
18
src/sync.d
18
src/sync.d
|
@ -64,6 +64,11 @@ private bool hasFileSize(const ref JSONValue item)
|
||||||
return ("size" in item) != null;
|
return ("size" in item) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool hasId(const ref JSONValue item)
|
||||||
|
{
|
||||||
|
return ("id" in item) != null;
|
||||||
|
}
|
||||||
|
|
||||||
// construct an Item struct from a JSON driveItem
|
// construct an Item struct from a JSON driveItem
|
||||||
private Item makeItem(const ref JSONValue driveItem)
|
private Item makeItem(const ref JSONValue driveItem)
|
||||||
{
|
{
|
||||||
|
@ -1107,7 +1112,8 @@ final class SyncEngine
|
||||||
if (e.httpStatusCode == 412) {
|
if (e.httpStatusCode == 412) {
|
||||||
// HTTP request returned status code 412 - ETag does not match current item's value
|
// HTTP request returned status code 412 - ETag does not match current item's value
|
||||||
// Delete record from the local database - file will be uploaded as a new file
|
// Delete record from the local database - file will be uploaded as a new file
|
||||||
log.vlog("OneDrive returned a 'HTTP 412 - Precondition Failed' - gracefully handling error");
|
log.vdebug("Simple Upload Replace Failed - OneDrive eTag / cTag match issue");
|
||||||
|
log.vlog("OneDrive returned a 'HTTP 412 - Precondition Failed' - gracefully handling error. Will upload as new file.");
|
||||||
itemdb.deleteById(item.driveId, item.id);
|
itemdb.deleteById(item.driveId, item.id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1128,7 +1134,8 @@ final class SyncEngine
|
||||||
if (e.httpStatusCode == 412) {
|
if (e.httpStatusCode == 412) {
|
||||||
// HTTP request returned status code 412 - ETag does not match current item's value
|
// HTTP request returned status code 412 - ETag does not match current item's value
|
||||||
// Delete record from the local database - file will be uploaded as a new file
|
// Delete record from the local database - file will be uploaded as a new file
|
||||||
log.vlog("OneDrive returned a 'HTTP 412 - Precondition Failed' - gracefully handling error");
|
log.vdebug("Simple Upload Replace Failed - OneDrive eTag / cTag match issue");
|
||||||
|
log.vlog("OneDrive returned a 'HTTP 412 - Precondition Failed' - gracefully handling error. Will upload as new file.");
|
||||||
itemdb.deleteById(item.driveId, item.id);
|
itemdb.deleteById(item.driveId, item.id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1661,13 +1668,18 @@ final class SyncEngine
|
||||||
if (e.httpStatusCode == 412) {
|
if (e.httpStatusCode == 412) {
|
||||||
// OneDrive threw a 412 error, most likely: ETag does not match current item's value
|
// OneDrive threw a 412 error, most likely: ETag does not match current item's value
|
||||||
// Retry without eTag
|
// Retry without eTag
|
||||||
log.vlog("OneDrive returned a 'HTTP 412 - Precondition Failed' - gracefully handling error");
|
log.vdebug("File Metadata Update Failed - OneDrive eTag / cTag match issue");
|
||||||
|
log.vlog("OneDrive returned a 'HTTP 412 - Precondition Failed' when attempting file time stamp update - gracefully handling error");
|
||||||
string nullTag = null;
|
string nullTag = null;
|
||||||
response = onedrive.updateById(driveId, id, data, nullTag);
|
response = onedrive.updateById(driveId, id, data, nullTag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Check if the response JSON has an 'id', otherwise makeItem() fails with 'Key not found: id'
|
||||||
|
if (hasId(response)) {
|
||||||
|
// save the updated response from OneDrive in the database
|
||||||
saveItem(response);
|
saveItem(response);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void saveItem(JSONValue jsonItem)
|
private void saveItem(JSONValue jsonItem)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue