Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update --get-O365-drive-id error handling #2266

Merged
merged 2 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/onedrive.d
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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
Expand Down
22 changes: 21 additions & 1 deletion src/sync.d
Original file line number Diff line number Diff line change
Expand Up @@ -6160,18 +6160,38 @@ 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 (;;) {
try {
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.
Expand Down