mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-19 22:25:03 +02:00
Catch unhandled API response errors when querying OneDrive Business Shared Folders (#1703)
* When syncing OneDrive Business Shared Folders, try the API query and catch any API error response, rather than blindly attempting the API query
This commit is contained in:
parent
4d25e68c65
commit
2f660ff7b0
54
src/sync.d
54
src/sync.d
|
@ -637,7 +637,32 @@ final class SyncEngine
|
||||||
if (syncBusinessFolders){
|
if (syncBusinessFolders){
|
||||||
// query OneDrive Business Shared Folders shared with me
|
// query OneDrive Business Shared Folders shared with me
|
||||||
log.vlog("Attempting to sync OneDrive Business Shared Folders");
|
log.vlog("Attempting to sync OneDrive Business Shared Folders");
|
||||||
JSONValue graphQuery = onedrive.getSharedWithMe();
|
JSONValue graphQuery;
|
||||||
|
try {
|
||||||
|
graphQuery = onedrive.getSharedWithMe();
|
||||||
|
} catch (OneDriveException e) {
|
||||||
|
if (e.httpStatusCode == 401) {
|
||||||
|
// HTTP request returned status code 401 (Unauthorized)
|
||||||
|
displayOneDriveErrorMessage(e.msg, getFunctionName!({}));
|
||||||
|
log.errorAndNotify("\nERROR: Check your configuration as your refresh_token may be empty or invalid. You may need to issue a --logout and re-authorise this client.\n");
|
||||||
|
// Must exit here
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
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.
|
||||||
|
handleOneDriveThrottleRequest();
|
||||||
|
// Retry original request by calling function again to avoid replicating any further error handling
|
||||||
|
log.vdebug("Retrying original request that generated the OneDrive HTTP 429 Response Code (Too Many Requests) - graphQuery = onedrive.getSharedWithMe();");
|
||||||
|
graphQuery = onedrive.getSharedWithMe();
|
||||||
|
}
|
||||||
|
if (e.httpStatusCode >= 500) {
|
||||||
|
// There was a HTTP 5xx Server Side Error
|
||||||
|
displayOneDriveErrorMessage(e.msg, getFunctionName!({}));
|
||||||
|
// Must exit here
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (graphQuery.type() == JSONType.object) {
|
if (graphQuery.type() == JSONType.object) {
|
||||||
string sharedFolderName;
|
string sharedFolderName;
|
||||||
foreach (searchResult; graphQuery["value"].array) {
|
foreach (searchResult; graphQuery["value"].array) {
|
||||||
|
@ -806,7 +831,32 @@ final class SyncEngine
|
||||||
if (syncBusinessFolders){
|
if (syncBusinessFolders){
|
||||||
log.vlog("Attempting to sync OneDrive Business Shared Folders");
|
log.vlog("Attempting to sync OneDrive Business Shared Folders");
|
||||||
// query OneDrive Business Shared Folders shared with me
|
// query OneDrive Business Shared Folders shared with me
|
||||||
JSONValue graphQuery = onedrive.getSharedWithMe();
|
JSONValue graphQuery;
|
||||||
|
try {
|
||||||
|
graphQuery = onedrive.getSharedWithMe();
|
||||||
|
} catch (OneDriveException e) {
|
||||||
|
if (e.httpStatusCode == 401) {
|
||||||
|
// HTTP request returned status code 401 (Unauthorized)
|
||||||
|
displayOneDriveErrorMessage(e.msg, getFunctionName!({}));
|
||||||
|
log.errorAndNotify("\nERROR: Check your configuration as your refresh_token may be empty or invalid. You may need to issue a --logout and re-authorise this client.\n");
|
||||||
|
// Must exit here
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
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.
|
||||||
|
handleOneDriveThrottleRequest();
|
||||||
|
// Retry original request by calling function again to avoid replicating any further error handling
|
||||||
|
log.vdebug("Retrying original request that generated the OneDrive HTTP 429 Response Code (Too Many Requests) - graphQuery = onedrive.getSharedWithMe();");
|
||||||
|
graphQuery = onedrive.getSharedWithMe();
|
||||||
|
}
|
||||||
|
if (e.httpStatusCode >= 500) {
|
||||||
|
// There was a HTTP 5xx Server Side Error
|
||||||
|
displayOneDriveErrorMessage(e.msg, getFunctionName!({}));
|
||||||
|
// Must exit here
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (graphQuery.type() == JSONType.object) {
|
if (graphQuery.type() == JSONType.object) {
|
||||||
// valid response from OneDrive
|
// valid response from OneDrive
|
||||||
string sharedFolderName;
|
string sharedFolderName;
|
||||||
|
|
Loading…
Reference in a new issue