Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve Key not found: 'id' when handling HTTP 412 - Precondition Failed (Issue #325) #329

Merged
merged 1 commit into from
Jan 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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