mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-08 00:42:13 +02:00
* Fix handling of 5xx responses from OneDrive when performing a session upload * Switch to same checks when doing non session upload so that OneDrive exceptions are thrown correctly * Remove a 'throw e' when curl times out * Remove a needless 'throw e' when a session upload cannot be found * Set the upload failed flag when OneDrive errors on session uploads
This commit is contained in:
parent
219fce2109
commit
5cd860a398
|
@ -364,7 +364,7 @@ final class OneDriveApi
|
||||||
http.contentLength = offsetSize;
|
http.contentLength = offsetSize;
|
||||||
auto response = perform();
|
auto response = perform();
|
||||||
// TODO: retry on 5xx errors
|
// TODO: retry on 5xx errors
|
||||||
checkHttpCode();
|
checkHttpCode(response);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -620,7 +620,6 @@ final class OneDriveApi
|
||||||
} catch (CurlException e) {
|
} catch (CurlException e) {
|
||||||
// Potentially Timeout was reached on handle error
|
// Potentially Timeout was reached on handle error
|
||||||
log.error("\nThere was a problem in accessing the Microsoft OneDrive service - Internet connectivity issue?\n");
|
log.error("\nThere was a problem in accessing the Microsoft OneDrive service - Internet connectivity issue?\n");
|
||||||
throw e;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONValue json;
|
JSONValue json;
|
||||||
|
@ -680,6 +679,7 @@ final class OneDriveApi
|
||||||
|
|
||||||
switch(http.statusLine.code)
|
switch(http.statusLine.code)
|
||||||
{
|
{
|
||||||
|
// 0 - OK ... HTTP2 version of 200 OK
|
||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
// 200 - OK
|
// 200 - OK
|
||||||
|
@ -776,6 +776,25 @@ final class OneDriveApi
|
||||||
{
|
{
|
||||||
switch(http.statusLine.code)
|
switch(http.statusLine.code)
|
||||||
{
|
{
|
||||||
|
// 0 - OK ... HTTP2 version of 200 OK
|
||||||
|
case 0:
|
||||||
|
break;
|
||||||
|
// 200 - OK
|
||||||
|
case 200:
|
||||||
|
// No Log ..
|
||||||
|
break;
|
||||||
|
// 201 - Created OK
|
||||||
|
// 202 - Accepted
|
||||||
|
// 204 - Deleted OK
|
||||||
|
case 201,202,204:
|
||||||
|
// No actions, but log if verbose logging
|
||||||
|
//log.vlog("OneDrive Response: '", http.statusLine.code, " - ", http.statusLine.reason, "'");
|
||||||
|
break;
|
||||||
|
|
||||||
|
// 302 - resource found and available at another location, redirect
|
||||||
|
case 302:
|
||||||
|
break;
|
||||||
|
|
||||||
// 400 - Bad Request
|
// 400 - Bad Request
|
||||||
case 400:
|
case 400:
|
||||||
// Bad Request .. how should we act?
|
// Bad Request .. how should we act?
|
||||||
|
|
|
@ -2417,7 +2417,8 @@ final class SyncEngine
|
||||||
} else {
|
} else {
|
||||||
// response is not valid JSON, an error was returned from OneDrive
|
// response is not valid JSON, an error was returned from OneDrive
|
||||||
log.fileOnly("Uploading new file ", path, " ... error");
|
log.fileOnly("Uploading new file ", path, " ... error");
|
||||||
writeln(" error");
|
writeln("error");
|
||||||
|
uploadFailed = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -2434,6 +2435,7 @@ final class SyncEngine
|
||||||
|
|
||||||
if (e.httpStatusCode >= 500) {
|
if (e.httpStatusCode >= 500) {
|
||||||
// OneDrive returned a 'HTTP 5xx Server Side Error' - gracefully handling error - error message already logged
|
// OneDrive returned a 'HTTP 5xx Server Side Error' - gracefully handling error - error message already logged
|
||||||
|
uploadFailed = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2709,14 +2711,19 @@ final class SyncEngine
|
||||||
// fileDetailsFromOneDrive is not valid JSON, an error was returned from OneDrive
|
// fileDetailsFromOneDrive is not valid JSON, an error was returned from OneDrive
|
||||||
log.error("ERROR: An error was returned from OneDrive and the resulting response is not a valid JSON object");
|
log.error("ERROR: An error was returned from OneDrive and the resulting response is not a valid JSON object");
|
||||||
log.error("ERROR: Increase logging verbosity to assist determining why.");
|
log.error("ERROR: Increase logging verbosity to assist determining why.");
|
||||||
|
uploadFailed = true;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Skip file - too large
|
// Skip file - too large
|
||||||
log.log("Skipping uploading this new file as it exceeds the maximum size allowed by OneDrive: ", path);
|
log.log("Skipping uploading this new file as it exceeds the maximum size allowed by OneDrive: ", path);
|
||||||
|
uploadFailed = true;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.log("Skipping uploading this new file as parent path is not in the database: ", path);
|
log.log("Skipping uploading this new file as parent path is not in the database: ", path);
|
||||||
|
uploadFailed = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
16
src/upload.d
16
src/upload.d
|
@ -89,8 +89,6 @@ struct UploadSession
|
||||||
if (e.httpStatusCode == 400) {
|
if (e.httpStatusCode == 400) {
|
||||||
log.vlog("Upload session not found");
|
log.vlog("Upload session not found");
|
||||||
return false;
|
return false;
|
||||||
} else {
|
|
||||||
throw e;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,14 +176,24 @@ struct UploadSession
|
||||||
fragSize,
|
fragSize,
|
||||||
fileSize
|
fileSize
|
||||||
);
|
);
|
||||||
|
} catch (OneDriveException e) {
|
||||||
|
// there was an error remove session file
|
||||||
|
if (exists(sessionFilePath)) {
|
||||||
|
remove(sessionFilePath);
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
// fragment uploaded without issue
|
||||||
|
if (response.type() == JSONType.object){
|
||||||
offset += fragmentSize;
|
offset += fragmentSize;
|
||||||
if (offset >= fileSize) break;
|
if (offset >= fileSize) break;
|
||||||
// update the session details
|
// update the session details
|
||||||
session["expirationDateTime"] = response["expirationDateTime"];
|
session["expirationDateTime"] = response["expirationDateTime"];
|
||||||
session["nextExpectedRanges"] = response["nextExpectedRanges"];
|
session["nextExpectedRanges"] = response["nextExpectedRanges"];
|
||||||
save();
|
save();
|
||||||
} catch (OneDriveException e) {
|
} else {
|
||||||
// there was an error remove session file
|
// not a JSON object
|
||||||
|
log.vlog("File upload session failed - invalid response from OneDrive");
|
||||||
if (exists(sessionFilePath)) {
|
if (exists(sessionFilePath)) {
|
||||||
remove(sessionFilePath);
|
remove(sessionFilePath);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue