mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-15 20:25:18 +02:00
do not throw on expired status token
This commit is contained in:
parent
947136cf62
commit
7257c4c9bf
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
18
src/sync.d
18
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue