mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-15 20:25:18 +02:00
Resolve database assertion failure due to authentication HTTP/1.1 400 Bad Request (#246)
* Enhance initialisation error handling to catch 4xx errors
This commit is contained in:
parent
eaedfac34a
commit
fc162b94e2
|
@ -144,10 +144,10 @@ function test_onedrive {
|
||||||
cd ..
|
cd ..
|
||||||
mkdir -p ~/.config/onedrive/
|
mkdir -p ~/.config/onedrive/
|
||||||
echo $ODP > ~/.config/onedrive/refresh_token
|
echo $ODP > ~/.config/onedrive/refresh_token
|
||||||
./onedrive --synchronize --verbose --syncdir=~/OneDriveALT
|
./onedrive --synchronize --verbose --syncdir '~/OneDriveALT'
|
||||||
# OneDrive Cleanup
|
# OneDrive Cleanup
|
||||||
rm -rf ~/OneDriveALT/*
|
rm -rf ~/OneDriveALT/*
|
||||||
./onedrive --synchronize --verbose --syncdir=~/OneDriveALT
|
./onedrive --synchronize --verbose --syncdir '~/OneDriveALT'
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
35
src/sync.d
35
src/sync.d
|
@ -6,6 +6,7 @@ import std.file, std.json, std.path;
|
||||||
import std.regex;
|
import std.regex;
|
||||||
import std.stdio, std.string, std.uni, std.uri;
|
import std.stdio, std.string, std.uni, std.uri;
|
||||||
import core.time, core.thread;
|
import core.time, core.thread;
|
||||||
|
import core.stdc.stdlib;
|
||||||
import config, itemdb, onedrive, selective, upload, util;
|
import config, itemdb, onedrive, selective, upload, util;
|
||||||
static import log;
|
static import log;
|
||||||
|
|
||||||
|
@ -179,9 +180,35 @@ final class SyncEngine
|
||||||
// Set accountType, defaultDriveId, defaultRootId & remainingFreeSpace once and reuse where possible
|
// Set accountType, defaultDriveId, defaultRootId & remainingFreeSpace once and reuse where possible
|
||||||
JSONValue oneDriveDetails;
|
JSONValue oneDriveDetails;
|
||||||
|
|
||||||
// Need to catch 5xx server side errors at initialization
|
// Need to catch 400 or 5xx server side errors at initialization
|
||||||
try {
|
try {
|
||||||
oneDriveDetails = onedrive.getDefaultDrive();
|
oneDriveDetails = onedrive.getDefaultDrive();
|
||||||
|
} catch (OneDriveException e) {
|
||||||
|
if (e.httpStatusCode == 400) {
|
||||||
|
// OneDrive responded with 400 error: Bad Request
|
||||||
|
log.error("\nERROR: OneDrive returned a 'HTTP 400 Bad Request' - Cannot Initialize Sync Engine");
|
||||||
|
// Check this
|
||||||
|
if (cfg.getValue("drive_id").length) {
|
||||||
|
log.error("ERROR: Check your 'drive_id' entry in your configuration file as it may be incorrect\n");
|
||||||
|
}
|
||||||
|
// Must exit here
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
if (e.httpStatusCode == 401) {
|
||||||
|
// HTTP request returned status code 401 (Unauthorized)
|
||||||
|
log.error("\nERROR: OneDrive returned a 'HTTP 401 Unauthorized' - Cannot Initialize Sync Engine");
|
||||||
|
log.error("ERROR: Check your configuration as your access token may be empty or invalid\n");
|
||||||
|
// Must exit here
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
if (e.httpStatusCode >= 500) {
|
||||||
|
// There was a HTTP 5xx Server Side Error
|
||||||
|
log.error("ERROR: OneDrive returned a 'HTTP 5xx Server Side Error' - Cannot Initialize Sync Engine");
|
||||||
|
// Must exit here
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Successfully got details from OneDrive without a server side error such as HTTP/1.1 504 Gateway Timeout
|
// Successfully got details from OneDrive without a server side error such as HTTP/1.1 504 Gateway Timeout
|
||||||
accountType = oneDriveDetails["driveType"].str;
|
accountType = oneDriveDetails["driveType"].str;
|
||||||
defaultDriveId = oneDriveDetails["id"].str;
|
defaultDriveId = oneDriveDetails["id"].str;
|
||||||
|
@ -203,12 +230,6 @@ final class SyncEngine
|
||||||
auto item = session.upload();
|
auto item = session.upload();
|
||||||
saveItem(item);
|
saveItem(item);
|
||||||
}
|
}
|
||||||
} catch (OneDriveException e) {
|
|
||||||
if (e.httpStatusCode >= 500) {
|
|
||||||
// There was a HTTP 5xx Server Side Error
|
|
||||||
log.error("ERROR: OneDrive returned a 'HTTP 5xx Server Side Error' - Cannot Initialize Sync Engine");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure noRemoteDelete if function is called
|
// Configure noRemoteDelete if function is called
|
||||||
|
|
Loading…
Reference in a new issue