diff --git a/src/main.d b/src/main.d index e09bcffd..5d71ce54 100644 --- a/src/main.d +++ b/src/main.d @@ -532,12 +532,13 @@ int main(string[] cliArgs) { // Do we perform a sync with OneDrive? if (notificationReceived || (currentTime - lastCheckTime > checkOnlineInterval) || (monitorLoopFullCount == 0)) { + // Increment monitorLoopFullCount + monitorLoopFullCount++; log.vdebug(loopStartOutputMessage); + log.vdebug("Loop Number: ", monitorLoopFullCount); log.log("Starting a sync with Microsoft OneDrive"); SysTime startFunctionProcessingTime = Clock.currTime(); log.vdebug("Start Monitor Loop Time: ", startFunctionProcessingTime); - // Increment monitorLoopFullCount - monitorLoopFullCount++; // Did the user specify --upload-only? if (appConfig.getValueBool("upload_only")) { diff --git a/src/onedrive.d b/src/onedrive.d index 4f078015..bf01a5f5 100644 --- a/src/onedrive.d +++ b/src/onedrive.d @@ -284,13 +284,13 @@ class OneDriveApi { } else { // Try and read the value from the appConfig if it is set, rather than trying to read the value from disk if (!appConfig.refreshToken.empty) { + log.vdebug("read token from appConfig"); refreshToken = appConfig.refreshToken; authorised = true; } else { // Try and read the file from disk try { refreshToken = readText(appConfig.refreshTokenFilePath); - // is the refresh_token empty? if (refreshToken.empty) { log.error("refreshToken exists but is empty: ", appConfig.refreshTokenFilePath); @@ -298,6 +298,8 @@ class OneDriveApi { } else { // existing token not empty authorised = true; + // update appConfig.refreshToken + appConfig.refreshToken = refreshToken; } } catch (FileException e) { authorised = authorise(); @@ -308,6 +310,11 @@ class OneDriveApi { authorised = false; } } + + if (refreshToken.empty) { + // PROBLEM + writeln("refreshToken is empty !!!!!!!!!! will cause 4xx errors"); + } } // Return if we are authorised log.vdebug("Authorised State: ", authorised); diff --git a/src/sync.d b/src/sync.d index 4a5fe422..3239037b 100644 --- a/src/sync.d +++ b/src/sync.d @@ -1773,12 +1773,16 @@ class SyncEngine { // Function variables JSONValue deltaChangesBundle; // Get the /delta data for this account | driveId | deltaLink combination + // Create a new API Instance for this thread and initialise it + OneDriveApi getDeltaQueryOneDriveApiInstance; + getDeltaQueryOneDriveApiInstance = new OneDriveApi(appConfig); + getDeltaQueryOneDriveApiInstance.initialise(); try { - deltaChangesBundle = oneDriveApiInstance.viewChangesByItemId(selectedDriveId, selectedItemId, providedDeltaLink); + deltaChangesBundle = getDeltaQueryOneDriveApiInstance.viewChangesByItemId(selectedDriveId, selectedItemId, providedDeltaLink); } catch (OneDriveException exception) { log.vdebug("deltaChangesBundle = oneDriveApiInstance.viewChangesByItemId() generated a OneDriveException"); - // display error and exit - defaultUnhandledHTTPErrorCode(exception); + // display error message + displayOneDriveErrorMessage(exception.msg, getFunctionName!({})); } // If the JSON response is a correct JSON object, and has an 'id' we can set these details