From 31629e697fc7a7c99715eecd1e61b3e0f0532942 Mon Sep 17 00:00:00 2001 From: abraunegg Date: Mon, 6 Apr 2020 19:40:42 +1000 Subject: [PATCH] Update error logging output to be consistent (#860) * Update error logging to be consistent when initialising fails * Update error logging output to handle HTML error response reasoning --- src/sync.d | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/sync.d b/src/sync.d index 872e4cfe..91b17044 100644 --- a/src/sync.d +++ b/src/sync.d @@ -279,18 +279,19 @@ final class SyncEngine log.vdebug("oneDriveDetails = onedrive.getDefaultDrive() generated a OneDriveException"); if (e.httpStatusCode == 400) { // OneDrive responded with 400 error: Bad Request - log.error("\nERROR: OneDrive returned a 'HTTP 400 Bad Request' - Cannot Initialize Sync Engine"); + displayOneDriveErrorMessage(e.msg); + // Check this if (cfg.getValueString("drive_id").length) { - log.error("ERROR: Check your 'drive_id' entry in your configuration file as it may be incorrect\n"); + log.error("\nERROR: Check your 'drive_id' entry in your configuration file as it may be incorrect\n"); } // Must exit here exit(-1); } if (e.httpStatusCode == 401) { // HTTP request returned status code 401 (Unauthorized) - log.error("\nERROR: OneDrive returned a 'HTTP 401 Unauthorized' - Cannot Initialize Sync Engine"); - log.error("ERROR: 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"); + displayOneDriveErrorMessage(e.msg); + log.error("\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); } @@ -305,7 +306,7 @@ final class SyncEngine } if (e.httpStatusCode >= 500) { // There was a HTTP 5xx Server Side Error - log.error("ERROR: OneDrive returned a 'HTTP 5xx Server Side Error' - Cannot Initialize Sync Engine"); + displayOneDriveErrorMessage(e.msg); // Must exit here exit(-1); } @@ -318,18 +319,18 @@ final class SyncEngine log.vdebug("oneDriveRootDetails = onedrive.getDefaultRoot() generated a OneDriveException"); if (e.httpStatusCode == 400) { // OneDrive responded with 400 error: Bad Request - log.error("\nERROR: OneDrive returned a 'HTTP 400 Bad Request' - Cannot Initialize Sync Engine"); + displayOneDriveErrorMessage(e.msg); // Check this if (cfg.getValueString("drive_id").length) { - log.error("ERROR: Check your 'drive_id' entry in your configuration file as it may be incorrect\n"); + log.error("\nERROR: Check your 'drive_id' entry in your configuration file as it may be incorrect\n"); } // Must exit here exit(-1); } if (e.httpStatusCode == 401) { // HTTP request returned status code 401 (Unauthorized) - log.error("\nERROR: OneDrive returned a 'HTTP 401 Unauthorized' - Cannot Initialize Sync Engine"); - log.error("ERROR: 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"); + displayOneDriveErrorMessage(e.msg); + log.error("\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); } @@ -344,7 +345,7 @@ final class SyncEngine } if (e.httpStatusCode >= 500) { // There was a HTTP 5xx Server Side Error - log.error("ERROR: OneDrive returned a 'HTTP 5xx Server Side Error' - Cannot Initialize Sync Engine"); + displayOneDriveErrorMessage(e.msg); // Must exit here exit(-1); } @@ -3709,12 +3710,21 @@ final class SyncEngine // Parse and display error message received from OneDrive private void displayOneDriveErrorMessage(string message) { - log.error("ERROR: OneDrive returned an error with the following message:"); + log.error("\nERROR: OneDrive returned an error with the following message:"); auto errorArray = splitLines(message); log.error(" Error Message: ", errorArray[0]); // extract 'message' as the reason JSONValue errorMessage = parseJSON(replace(message, errorArray[0], "")); - log.error(" Error Reason: ", errorMessage["error"]["message"].str); + string errorReason = errorMessage["error"]["message"].str; + // display reason + if (errorReason.startsWith("