mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-19 14:15:25 +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
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
18
src/sync.d
18
src/sync.d
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue