mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-08 08:52:15 +02:00
Update --get-O365-drive-id error handling (#2266)
* Ensure a 'Personal' account type is not being used * If the /sites?search API cannot be found, display a more appropriate error message
This commit is contained in:
parent
4db2ec02fc
commit
678add91f8
|
@ -617,6 +617,12 @@ final class OneDriveApi
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string getSiteSearchUrl()
|
||||||
|
{
|
||||||
|
// Return the actual siteSearchUrl being used and/or requested when performing 'siteQuery = onedrive.o365SiteSearch(nextLink);' call
|
||||||
|
return .siteSearchUrl;
|
||||||
|
}
|
||||||
|
|
||||||
ulong getRetryAfterValue()
|
ulong getRetryAfterValue()
|
||||||
{
|
{
|
||||||
// Return the current value of retryAfterValue if it has been set to something other than 0
|
// Return the current value of retryAfterValue if it has been set to something other than 0
|
||||||
|
@ -1780,7 +1786,7 @@ final class OneDriveApi
|
||||||
case 403:
|
case 403:
|
||||||
// OneDrive responded that the user is forbidden
|
// OneDrive responded that the user is forbidden
|
||||||
log.vlog("OneDrive returned a 'HTTP 403 - Forbidden' - gracefully handling error");
|
log.vlog("OneDrive returned a 'HTTP 403 - Forbidden' - gracefully handling error");
|
||||||
// Throw this as a specific exception so this is caught when performing sync.o365SiteSearch
|
// Throw this as a specific exception so this is caught when performing 'siteQuery = onedrive.o365SiteSearch(nextLink);' call
|
||||||
throw new OneDriveException(http.statusLine.code, http.statusLine.reason, response);
|
throw new OneDriveException(http.statusLine.code, http.statusLine.reason, response);
|
||||||
|
|
||||||
// 412 - Precondition Failed
|
// 412 - Precondition Failed
|
||||||
|
|
22
src/sync.d
22
src/sync.d
|
@ -6160,6 +6160,13 @@ final class SyncEngine
|
||||||
string nextLink;
|
string nextLink;
|
||||||
string[] siteSearchResults;
|
string[] siteSearchResults;
|
||||||
|
|
||||||
|
// The account type must not be a personal account type
|
||||||
|
if (accountType == "personal"){
|
||||||
|
log.error("ERROR: A OneDrive Personal Account cannot be used with --get-O365-drive-id. Please re-authenticate your client using a OneDrive Business Account.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// What query are we performing?
|
||||||
log.log("Office 365 Library Name Query: ", o365SharedLibraryName);
|
log.log("Office 365 Library Name Query: ", o365SharedLibraryName);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -6167,11 +6174,24 @@ final class SyncEngine
|
||||||
siteQuery = onedrive.o365SiteSearch(nextLink);
|
siteQuery = onedrive.o365SiteSearch(nextLink);
|
||||||
} catch (OneDriveException e) {
|
} catch (OneDriveException e) {
|
||||||
log.error("ERROR: Query of OneDrive for Office 365 Library Name failed");
|
log.error("ERROR: Query of OneDrive for Office 365 Library Name failed");
|
||||||
|
// Forbidden - most likely authentication scope needs to be updated
|
||||||
if (e.httpStatusCode == 403) {
|
if (e.httpStatusCode == 403) {
|
||||||
// Forbidden - most likely authentication scope needs to be updated
|
|
||||||
log.error("ERROR: Authentication scope needs to be updated. Use --reauth and re-authenticate client.");
|
log.error("ERROR: Authentication scope needs to be updated. Use --reauth and re-authenticate client.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Requested resource cannot be found
|
||||||
|
if (e.httpStatusCode == 404) {
|
||||||
|
string siteSearchUrl;
|
||||||
|
if (nextLink.empty) {
|
||||||
|
siteSearchUrl = onedrive.getSiteSearchUrl();
|
||||||
|
} else {
|
||||||
|
siteSearchUrl = nextLink;
|
||||||
|
}
|
||||||
|
// log the error
|
||||||
|
log.error("ERROR: Your OneDrive Account and Authentication Scope cannot access this OneDrive API: ", siteSearchUrl);
|
||||||
|
log.error("ERROR: To resolve, please discuss this issue with whomever supports your OneDrive and SharePoint environment.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
// HTTP request returned status code 429 (Too Many Requests)
|
// HTTP request returned status code 429 (Too Many Requests)
|
||||||
if (e.httpStatusCode == 429) {
|
if (e.httpStatusCode == 429) {
|
||||||
// HTTP request returned status code 429 (Too Many Requests). We need to leverage the response Retry-After HTTP header to ensure minimum delay until the throttle is removed.
|
// HTTP request returned status code 429 (Too Many Requests). We need to leverage the response Retry-After HTTP header to ensure minimum delay until the throttle is removed.
|
||||||
|
|
Loading…
Reference in a new issue