From e47f289aac0573e1ec3bcc162d36d6e5f70bc712 Mon Sep 17 00:00:00 2001 From: abraunegg Date: Sun, 16 Mar 2025 12:09:48 +1100 Subject: [PATCH] Support localizedMessage error messages provided by Microsoft Graph API (#3153) * Support localizedMessage error messages in application output if this is provided in the JSON response from Microsoft Graph API --- src/util.d | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/util.d b/src/util.d index 57593d56..5d24b161 100644 --- a/src/util.d +++ b/src/util.d @@ -645,7 +645,7 @@ void displayOneDriveErrorMessage(string message, string callingFunction) { addLogEntry(); addLogEntry("ERROR: Microsoft OneDrive API returned an error with the following message:"); auto errorArray = splitLines(message); - addLogEntry(" Error Message: " ~ to!string(errorArray[0])); + addLogEntry(" Error Message: " ~ to!string(errorArray[0])); // Extract 'message' as the reason JSONValue errorMessage = parseJSON(replace(message, errorArray[0], "")); @@ -656,6 +656,7 @@ void displayOneDriveErrorMessage(string message, string callingFunction) { string errorCode; string requestDate; string requestId; + string localizedMessage; // set the reason for the error try { @@ -673,15 +674,23 @@ void displayOneDriveErrorMessage(string message, string callingFunction) { // we dont want to do anything here } + // Microsoft has started adding 'localizedMessage' to error JSON responses. If this is available, use this + try { + // Use ["error"]["localizedMessage"] as localised reason + localizedMessage = errorMessage["error"]["localizedMessage"].str; + } catch (JSONException e) { + // we dont want to do anything here if not available + } + // Display the error reason if (errorReason.startsWith("