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:
abraunegg 2022-12-16 06:08:46 +11:00 committed by GitHub
parent 4db2ec02fc
commit 678add91f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 2 deletions

View file

@ -616,6 +616,12 @@ final class OneDriveApi
redeemToken(c.front);
return true;
}
string getSiteSearchUrl()
{
// Return the actual siteSearchUrl being used and/or requested when performing 'siteQuery = onedrive.o365SiteSearch(nextLink);' call
return .siteSearchUrl;
}
ulong getRetryAfterValue()
{
@ -1780,7 +1786,7 @@ final class OneDriveApi
case 403:
// OneDrive responded that the user is forbidden
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);
// 412 - Precondition Failed

View file

@ -6160,6 +6160,13 @@ final class SyncEngine
string nextLink;
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);
for (;;) {
@ -6167,11 +6174,24 @@ final class SyncEngine
siteQuery = onedrive.o365SiteSearch(nextLink);
} catch (OneDriveException e) {
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) {
// Forbidden - most likely authentication scope needs to be updated
log.error("ERROR: Authentication scope needs to be updated. Use --reauth and re-authenticate client.");
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)
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.