From 9e2123249aa9db794327871d3a48a5e543ed63e5 Mon Sep 17 00:00:00 2001 From: skilion Date: Thu, 15 Jun 2017 13:02:04 +0200 Subject: [PATCH] do not check token status during initialization --- src/onedrive.d | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/onedrive.d b/src/onedrive.d index 07a2d14a..14f96ab3 100644 --- a/src/onedrive.d +++ b/src/onedrive.d @@ -13,6 +13,7 @@ private immutable { string driveUrl = "https://graph.microsoft.com/v1.0/me/drive"; string itemByIdUrl = "https://graph.microsoft.com/v1.0/me/drive/items/"; string itemByPathUrl = "https://graph.microsoft.com/v1.0/me/drive/root:/"; + string driveByIdUrl = "https://graph.microsoft.com/v1.0/me/drives/"; } class OneDriveException: Exception @@ -64,15 +65,8 @@ final class OneDriveApi { try { refreshToken = readText(cfg.refreshTokenFilePath); - getDefaultDrive(); } catch (FileException e) { return authorize(); - } catch (OneDriveException e) { - if (e.httpStatusCode == 400 || e.httpStatusCode == 401) { - log.log("Refresh token invalid"); - return authorize(); - } - throw e; } return true; } @@ -104,11 +98,11 @@ final class OneDriveApi } // https://dev.onedrive.com/items/view_delta.htm - JSONValue viewChangesById(const(char)[] id, const(char)[] deltaLink) + JSONValue viewChangesById(const(char)[] driveId, const(char)[] id, const(char)[] deltaLink) { checkAccessTokenExpired(); if (deltaLink) return get(deltaLink); - const(char)[] url = itemByIdUrl ~ id ~ "/delta"; + const(char)[] url = driveByIdUrl ~ driveId ~ "/items/" ~ id ~ "/delta"; url ~= "?select=id,name,eTag,cTag,deleted,file,folder,root,fileSystemInfo,remoteItem,parentReference"; return get(url); } @@ -252,8 +246,15 @@ final class OneDriveApi private void checkAccessTokenExpired() { - if (Clock.currTime() >= accessTokenExpiration) { - newToken(); + try { + if (Clock.currTime() >= accessTokenExpiration) { + newToken(); + } + } catch (OneDriveException e) { + if (e.httpStatusCode == 400 || e.httpStatusCode == 401) { + e.msg ~= "\nRefresh token invalid, use --logout to authorize the client again"; + } + throw e; } }