Skip to content

Commit

Permalink
Update code to align to v2.4.25 exception.httpStatusCode handling
Browse files Browse the repository at this point in the history
* Update code to align to v2.4.25 exception.httpStatusCode handling
  • Loading branch information
abraunegg committed Apr 13, 2024
1 parent ec933af commit 295a734
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 51 deletions.
5 changes: 2 additions & 3 deletions src/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -1411,9 +1411,8 @@ extern(C) nothrow @nogc @system void exitHandler(int value) {
try {
assumeNoGC ( () {
addLogEntry("Got termination signal, performing clean up");
// Wait for all parallel jobs that depend on the database to complete
addLogEntry("Waiting for any existing upload|download process to complete");
taskPool.finish(true);
// Force kill any running threads as ^C was used
taskPool.finish(false);
// Was itemDb initialised?
if (itemDB.isDatabaseInitialised()) {
// Make sure the .wal file is incorporated into the main db before we exit
Expand Down
20 changes: 12 additions & 8 deletions src/onedrive.d
Original file line number Diff line number Diff line change
Expand Up @@ -1238,8 +1238,8 @@ class OneDriveApi {
// https://stackoverflow.com/questions/45829588/brew-install-fails-curl77-error-setting-certificate-verify
// https://forum.dlang.org/post/vwvkbubufexgeuaxhqfl@forum.dlang.org

addLogEntry("Problem with reading the SSL CA cert via libcurl - please repair your system SSL CA Certificates");
throw new OneDriveError("OneDrive operation encounter curl lib issue");
addLogEntry("Problem with reading the local SSL CA cert via libcurl - please repair your system SSL CA Certificates");
throw new OneDriveError("OneDrive operation encountered an issue with libcurl reading the local SSL CA Certificates");
} else {
// Was this a curl initialization error?
if (canFind(errorMessage, "Failed initialization on handle")) {
Expand Down Expand Up @@ -1286,6 +1286,7 @@ class OneDriveApi {
415 Unsupported Media Type The content type of the request is a format that is not supported by the service.
416 Requested Range Not Satisfiable The specified byte range is invalid or unavailable.
422 Unprocessable Entity Cannot process the request because it is semantically incorrect.
423 Locked The file is currently checked out or locked for editing by another user
429 Too Many Requests Client application has been throttled and should not attempt to repeat the request until an amount of time has elapsed.
500 Internal Server Error There was an internal server error while processing the request.
Expand Down Expand Up @@ -1322,21 +1323,25 @@ class OneDriveApi {
// 100 - Continue
case 100:
break;
// 429 - Too Many Requests
case 429:
// 408 - Request Time Out
// 429 - Too Many Requests, backoff
case 408,429:
// If OneDrive sends a status code 429 then this function will be used to process the Retry-After response header which contains the value by which we need to wait
addLogEntry("Handling a OneDrive HTTP 429 Response Code (Too Many Requests) - Internal Thread ID: " ~ to!string(internalThreadId));
if (exception.httpStatusCode == 408) {
addLogEntry("Handling a OneDrive HTTP 408 Response Code (Request Time Out) - Internal Thread ID: " ~ to!string(internalThreadId));
} else {
addLogEntry("Handling a OneDrive HTTP 429 Response Code (Too Many Requests) - Internal Thread ID: " ~ to!string(internalThreadId));
}
// Read in the Retry-After HTTP header as set and delay as per this value before retrying the request
thisBackOffInterval = response.getRetryAfterValue();
addLogEntry("Using Retry-After Value = " ~ to!string(thisBackOffInterval), ["debug"]);
addLogEntry("Using Retry-After Value = " ~ to!string(thisBackOffInterval));
transientError = true;
break;
// Transient errors
// 408 - Request Time Out
// 503 - Service Unavailable
// 504 - Gateway Timeout
case 408,503,504:
case 503,504:
// The server, while acting as a proxy, did not receive a timely response from the upstream server it needed to access in attempting to complete the request
auto errorArray = splitLines(exception.msg);
addLogEntry(to!string(errorArray[0]) ~ " when attempting to query the OneDrive API Service - retrying applicable request in 30 seconds - Internal Thread ID: " ~ to!string(internalThreadId));
Expand All @@ -1347,7 +1352,6 @@ class OneDriveApi {
break;
// Default
default:
addLogEntry("DEFAULT HANDLER (OneDriveAPI exception) - TO REMOVE");
// This exception should be then passed back to the original calling function for handling a OneDriveException
throw new OneDriveException(curlEngine.http.statusLine.code, curlEngine.http.statusLine.reason, response);
}
Expand Down
Loading

0 comments on commit 295a734

Please sign in to comment.