mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-17 21:26:41 +02:00
Fix application crash with --get-O365-drive-id when API response is restricted (#1198)
* Check OneDrive API response for required elements before attempting to use elements for next query
This commit is contained in:
parent
8c6d1d19b8
commit
62a2b4f393
68
src/sync.d
68
src/sync.d
|
@ -5360,37 +5360,47 @@ final class SyncEngine
|
||||||
foreach (searchResult; siteQuery["value"].array) {
|
foreach (searchResult; siteQuery["value"].array) {
|
||||||
// Need an 'exclusive' match here with o365SharedLibraryName as entered
|
// Need an 'exclusive' match here with o365SharedLibraryName as entered
|
||||||
log.vdebug("Found O365 Site: ", searchResult);
|
log.vdebug("Found O365 Site: ", searchResult);
|
||||||
if (o365SharedLibraryName == searchResult["displayName"].str){
|
|
||||||
// 'displayName' matches search request
|
// 'displayName', 'id' and 'webUrl' have to be present in the search result record
|
||||||
site_id = searchResult["id"].str;
|
if (("displayName" in searchResult) && ("id" in searchResult) && ("webUrl" in searchResult)) {
|
||||||
webUrl = searchResult["webUrl"].str;
|
if (o365SharedLibraryName == searchResult["displayName"].str){
|
||||||
JSONValue siteDriveQuery;
|
// 'displayName' matches search request
|
||||||
|
site_id = searchResult["id"].str;
|
||||||
try {
|
webUrl = searchResult["webUrl"].str;
|
||||||
siteDriveQuery = onedrive.o365SiteDrives(site_id);
|
JSONValue siteDriveQuery;
|
||||||
} catch (OneDriveException e) {
|
|
||||||
log.error("ERROR: Query of OneDrive for Office Site ID failed");
|
try {
|
||||||
// display what the error is
|
siteDriveQuery = onedrive.o365SiteDrives(site_id);
|
||||||
displayOneDriveErrorMessage(e.msg, getFunctionName!({}));
|
} catch (OneDriveException e) {
|
||||||
return;
|
log.error("ERROR: Query of OneDrive for Office Site ID failed");
|
||||||
}
|
// display what the error is
|
||||||
|
displayOneDriveErrorMessage(e.msg, getFunctionName!({}));
|
||||||
// is siteDriveQuery a valid JSON object & contain data we can use?
|
return;
|
||||||
if ((siteDriveQuery.type() == JSONType.object) && ("value" in siteDriveQuery)) {
|
}
|
||||||
// valid JSON object
|
|
||||||
foreach (driveResult; siteDriveQuery["value"].array) {
|
// is siteDriveQuery a valid JSON object & contain data we can use?
|
||||||
// Display results
|
if ((siteDriveQuery.type() == JSONType.object) && ("value" in siteDriveQuery)) {
|
||||||
found = true;
|
// valid JSON object
|
||||||
writeln("SiteName: ", searchResult["displayName"].str);
|
foreach (driveResult; siteDriveQuery["value"].array) {
|
||||||
writeln("drive_id: ", driveResult["id"].str);
|
// Display results
|
||||||
writeln("URL: ", webUrl);
|
found = true;
|
||||||
|
writeln("SiteName: ", searchResult["displayName"].str);
|
||||||
|
writeln("drive_id: ", driveResult["id"].str);
|
||||||
|
writeln("URL: ", webUrl);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// not a valid JSON object
|
||||||
|
log.error("ERROR: There was an error performing this operation on OneDrive");
|
||||||
|
log.error("ERROR: Increase logging verbosity to assist determining why.");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// not a valid JSON object
|
|
||||||
log.error("ERROR: There was an error performing this operation on OneDrive");
|
|
||||||
log.error("ERROR: Increase logging verbosity to assist determining why.");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// 'displayName' not present in JSON results
|
||||||
|
log.error("ERROR: The results returned from OneDrive API do not contain the required items to match. Please check your permissions with your site administrator.");
|
||||||
|
log.error("ERROR: Your site security settings is preventing the following details from being accessed: 'displayName', 'id' and 'webUrl'");
|
||||||
|
log.error("ERROR: To debug this further, please use --verbose --verbose to provide insight as to what details are actually returned.");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue