Skip to content

Commit

Permalink
(GH-220) Improve how we check for errors in Zoom API responses to ac…
Browse files Browse the repository at this point in the history
…count for the fact that error JSON from Contact Center is slightly different
  • Loading branch information
Jericho committed Oct 26, 2024
1 parent 427af4a commit 7cc82ea
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions Source/ZoomNet/Extensions/Internal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,14 @@ internal static DiagnosticInfo GetDiagnosticInfo(this IResponse response)
}
]
}
There are some cases where error information is returned in a JSON string structured slightly differently.
For instance, ContactCenter endpoints return error information like this:
{
"status":false,
"errorCode":"401", <-- Notice this node contains a string
"errorMessage":"Contact Center has not been enabled for this account."
}
*/

try
Expand All @@ -744,12 +752,25 @@ internal static DiagnosticInfo GetDiagnosticInfo(this IResponse response)
errorMessage = jsonResponse.TryGetProperty("message", out JsonElement jsonErrorMessage) ? jsonErrorMessage.GetString() : errorCode.HasValue ? $"Error code: {errorCode}" : errorMessage;
if (jsonResponse.TryGetProperty("errors", out JsonElement jsonErrorDetails))
{
var errorDetails = string.Join(
" ",
jsonErrorDetails
.EnumerateArray()
.Select(jsonErrorDetail => jsonErrorDetail.TryGetProperty("message", out JsonElement jsonErrorMessage) ? jsonErrorMessage.GetString() : string.Empty)
.Where(message => !string.IsNullOrEmpty(message)));
if (rootJsonElement.TryGetProperty("code", out JsonElement codeJsonProperty)) errorCode = codeJsonProperty.GetInt32();
else if (rootJsonElement.TryGetProperty("errorCode", out JsonElement errorCodeJsonProperty)) errorCode = int.Parse(errorCodeJsonProperty.GetString());

if (rootJsonElement.TryGetProperty("message", out JsonElement messageJsonProperty)) errorMessage = messageJsonProperty.GetString();
else if (rootJsonElement.TryGetProperty("errorMessage", out JsonElement errorMessageJsonProperty)) errorMessage = errorMessageJsonProperty.GetString();
else if (errorCode.HasValue) errorMessage = $"Error code: {errorCode}";

if (rootJsonElement.TryGetProperty("errors", out JsonElement jsonErrorDetails))
{
var errorDetails = string.Join(
" ",
jsonErrorDetails
.EnumerateArray()
.Select(jsonErrorDetail =>
{
var errorDetail = jsonErrorDetail.TryGetProperty("message", out JsonElement jsonErrorMessage) ? jsonErrorMessage.GetString() : string.Empty;
return errorDetail;
})
.Where(message => !string.IsNullOrEmpty(message)));

if (!string.IsNullOrEmpty(errorDetails)) errorMessage += $" {errorDetails}";
}
Expand Down

0 comments on commit 7cc82ea

Please sign in to comment.