mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-11 10:22:21 +02:00
* Add JSON response checks in the event OneDrive sends malformed data
This commit is contained in:
parent
25d2f7284f
commit
c6923cdf29
14
src/upload.d
14
src/upload.d
|
@ -75,6 +75,7 @@ struct UploadSession
|
||||||
try {
|
try {
|
||||||
response = onedrive.requestUploadStatus(session["uploadUrl"].str);
|
response = onedrive.requestUploadStatus(session["uploadUrl"].str);
|
||||||
} catch (OneDriveException e) {
|
} catch (OneDriveException e) {
|
||||||
|
// handle any onedrive error response
|
||||||
if (e.httpStatusCode == 400) {
|
if (e.httpStatusCode == 400) {
|
||||||
log.vlog("Upload session not found");
|
log.vlog("Upload session not found");
|
||||||
return false;
|
return false;
|
||||||
|
@ -82,12 +83,25 @@ struct UploadSession
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// do we have a valid response from OneDrive?
|
||||||
|
if (response.object()){
|
||||||
|
// JSON object
|
||||||
|
if (("expirationDateTime" in response) && ("nextExpectedRanges" in response)){
|
||||||
|
// has the elements we need
|
||||||
session["expirationDateTime"] = response["expirationDateTime"];
|
session["expirationDateTime"] = response["expirationDateTime"];
|
||||||
session["nextExpectedRanges"] = response["nextExpectedRanges"];
|
session["nextExpectedRanges"] = response["nextExpectedRanges"];
|
||||||
if (session["nextExpectedRanges"].array.length == 0) {
|
if (session["nextExpectedRanges"].array.length == 0) {
|
||||||
log.vlog("The upload session is completed");
|
log.vlog("The upload session is completed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// bad data
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// not a JSON object
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// unable to read the local file
|
// unable to read the local file
|
||||||
|
|
Loading…
Reference in a new issue