Skip to content

Commit

Permalink
Update sync.d (#329)
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
abraunegg authored Jan 5, 2019
1 parent 46ef8ed commit ddc5d60
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/sync.d
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ private bool hasFileSize(const ref JSONValue item)
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
private Item makeItem(const ref JSONValue driveItem)
{
Expand Down Expand Up @@ -1107,7 +1112,8 @@ final class SyncEngine
if (e.httpStatusCode == 412) {
// 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
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);
return;
}
Expand All @@ -1128,7 +1134,8 @@ final class SyncEngine
if (e.httpStatusCode == 412) {
// 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
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);
return;
}
Expand Down Expand Up @@ -1661,12 +1668,17 @@ final class SyncEngine
if (e.httpStatusCode == 412) {
// OneDrive threw a 412 error, most likely: ETag does not match current item's value
// 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;
response = onedrive.updateById(driveId, id, data, nullTag);
}
}
saveItem(response);
// 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);
}
}

private void saveItem(JSONValue jsonItem)
Expand Down

0 comments on commit ddc5d60

Please sign in to comment.