From 7257c4c9bfb07efe4e333f562868e2ad80b739d3 Mon Sep 17 00:00:00 2001 From: skilion Date: Wed, 14 Dec 2016 15:17:20 +0100 Subject: [PATCH] do not throw on expired status token --- src/onedrive.d | 15 +++++++-------- src/sync.d | 18 +++++++++++++++--- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/onedrive.d b/src/onedrive.d index 84b90107..d07abd1b 100644 --- a/src/onedrive.d +++ b/src/onedrive.d @@ -15,8 +15,7 @@ private immutable { class OneDriveException: Exception { - // HTTP status code - int code; + int httpStatusCode; // error details JSONValue error; @@ -25,19 +24,19 @@ class OneDriveException: Exception super(msg, file, line, next); } - @safe pure this(int code, string reason, string file = __FILE__, size_t line = __LINE__) + @safe pure this(int httpStatusCode, string reason, string file = __FILE__, size_t line = __LINE__) { - this.code = code; + this.httpStatusCode = httpStatusCode; this.error = error; - string msg = format("HTTP request returned status code %d (%s)", code, reason); + string msg = format("HTTP request returned status code %d (%s)", httpStatusCode, reason); super(msg, file, line, next); } - this(int code, string reason, ref const JSONValue error, string file = __FILE__, size_t line = __LINE__) + this(int httpStatusCode, string reason, ref const JSONValue error, string file = __FILE__, size_t line = __LINE__) { - this.code = code; + this.httpStatusCode = httpStatusCode; this.error = error; - string msg = format("HTTP request returned status code %d (%s)\n%s", code, reason, toJSON(&error, true)); + string msg = format("HTTP request returned status code %d (%s)\n%s", httpStatusCode, reason, toJSON(&error, true)); super(msg, file, line, next); } } diff --git a/src/sync.d b/src/sync.d index 1789e777..994817c6 100644 --- a/src/sync.d +++ b/src/sync.d @@ -91,7 +91,19 @@ final class SyncEngine try { JSONValue changes; do { - changes = onedrive.viewChangesByPath("/", statusToken); + // get changes from the server + try { + changes = onedrive.viewChangesByPath("/", statusToken); + } catch (OneDriveException e) { + if (e.httpStatusCode == 410) { + log.log("Status token expired, resyncing"); + statusToken = null; + continue; + } + else { + throw e; + } + } foreach (item; changes["value"].array) { applyDifference(item); } @@ -497,7 +509,7 @@ final class SyncEngine try { onedrive.deleteById(item.id, item.eTag); } catch (OneDriveException e) { - if (e.code == 404) log.log(e.msg); + if (e.httpStatusCode == 404) log.log(e.msg); else throw e; } itemdb.deleteById(item.id); @@ -575,7 +587,7 @@ final class SyncEngine try { uploadDeleteItem(item, path); } catch (OneDriveException e) { - if (e.code == 404) log.log(e.msg); + if (e.httpStatusCode == 404) log.log(e.msg); else throw e; } }