Resolve Key not found: expirationDateTime on session resume (Issue #174) (#176)

* Handle an invalid response on session resume when a 4xx / 5xx response is generated from the OneDrive service
This commit is contained in:
abraunegg 2018-10-04 09:38:23 +10:00 committed by GitHub
parent 14b2de8f4c
commit 74b9163b06
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -53,6 +53,10 @@ struct UploadSession
if (exists(sessionFilePath)) {
log.vlog("Trying to restore the upload session ...");
session = readText(sessionFilePath).parseJSON();
// Check the session resume file for expirationDateTime
if ("expirationDateTime" in session){
// expirationDateTime in the file
auto expiration = SysTime.fromISOExtString(session["expirationDateTime"].str);
if (expiration < Clock.currTime()) {
log.vlog("The upload session is expired");
@ -87,6 +91,13 @@ struct UploadSession
return true;
} else {
// unable to read the local file
log.vlog("Restore file upload session failed - unable to read the local file");
remove(sessionFilePath);
return false;
}
} else {
// session file contains an error - cant resume
log.vlog("Restore file upload session failed - cleaning up session resume");
remove(sessionFilePath);
return false;
}
@ -108,6 +119,8 @@ struct UploadSession
while (true) {
p.next();
long fragSize = fragmentSize < fileSize - offset ? fragmentSize : fileSize - offset;
// If the resume upload fails, we need to check for a return code here
try {
response = onedrive.uploadFragment(
session["uploadUrl"].str,
session["localPath"].str,
@ -117,10 +130,15 @@ struct UploadSession
);
offset += fragmentSize;
if (offset >= fileSize) break;
// update the session
// update the session details
session["expirationDateTime"] = response["expirationDateTime"];
session["nextExpectedRanges"] = response["nextExpectedRanges"];
save();
} catch (OneDriveException e) {
// there was an error remove session file
remove(sessionFilePath);
return response;
}
}
// upload complete
p.next();