do not throw on expired status token

This commit is contained in:
skilion 2016-12-14 15:17:20 +01:00
parent 947136cf62
commit 7257c4c9bf
2 changed files with 22 additions and 11 deletions

View file

@ -15,8 +15,7 @@ private immutable {
class OneDriveException: Exception class OneDriveException: Exception
{ {
// HTTP status code int httpStatusCode;
int code;
// error details // error details
JSONValue error; JSONValue error;
@ -25,19 +24,19 @@ class OneDriveException: Exception
super(msg, file, line, next); 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; 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); 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; 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); super(msg, file, line, next);
} }
} }

View file

@ -91,7 +91,19 @@ final class SyncEngine
try { try {
JSONValue changes; JSONValue changes;
do { 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) { foreach (item; changes["value"].array) {
applyDifference(item); applyDifference(item);
} }
@ -497,7 +509,7 @@ final class SyncEngine
try { try {
onedrive.deleteById(item.id, item.eTag); onedrive.deleteById(item.id, item.eTag);
} catch (OneDriveException e) { } catch (OneDriveException e) {
if (e.code == 404) log.log(e.msg); if (e.httpStatusCode == 404) log.log(e.msg);
else throw e; else throw e;
} }
itemdb.deleteById(item.id); itemdb.deleteById(item.id);
@ -575,7 +587,7 @@ final class SyncEngine
try { try {
uploadDeleteItem(item, path); uploadDeleteItem(item, path);
} catch (OneDriveException e) { } catch (OneDriveException e) {
if (e.code == 404) log.log(e.msg); if (e.httpStatusCode == 404) log.log(e.msg);
else throw e; else throw e;
} }
} }