From d0209d8dbcb6c0ebca5fcb3dc7b62d1bea519df8 Mon Sep 17 00:00:00 2001 From: abraunegg Date: Mon, 16 Jul 2018 09:58:36 +1000 Subject: [PATCH] Gracefully handle OneDrive account password change (#73) * Gracefully handle OneDrive account password change rather than crashing if authorization token is now invalid --- src/main.d | 12 +++++++++++- src/onedrive.d | 1 - 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main.d b/src/main.d index a5992c1d..8be2fe61 100644 --- a/src/main.d +++ b/src/main.d @@ -192,7 +192,17 @@ int main(string[] args) // Initialise the sync engine log.log("Initializing the Synchronization Engine ..."); auto sync = new SyncEngine(cfg, onedrive, itemdb, selectiveSync); - sync.init(); + + try { + sync.init(); + } catch (OneDriveException e) { + if (e.httpStatusCode == 400 || e.httpStatusCode == 401) { + // Authorization is invalid + log.log("\nAuthorization token invalid, use --logout to authorize the client again\n"); + onedrive.http.shutdown(); + return EXIT_FAILURE; + } + } // Do we need to validate the syncDir to check for the presence of a '.nosync' file if (checkMount) { diff --git a/src/onedrive.d b/src/onedrive.d index 9da9bb42..ef6c61c2 100644 --- a/src/onedrive.d +++ b/src/onedrive.d @@ -294,7 +294,6 @@ final class OneDriveApi if (e.httpStatusCode == 400 || e.httpStatusCode == 401) { e.msg ~= "\nRefresh token invalid, use --logout to authorize the client again"; } - throw e; } }