Skip to content

Commit

Permalink
(GH-220) Improve how we check for errors in Zoom API responses to acc…
Browse files Browse the repository at this point in the history
…ount for the fact that error JSON from Contact Center is slightly different
  • Loading branch information
Jericho committed Dec 20, 2024
1 parent b3322b1 commit aa6e621
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions Source/ZoomNet/Extensions/Internal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -733,15 +733,28 @@ 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
{
var jsonResponse = await message.Content.ParseZoomResponseAsync().ConfigureAwait(false);
if (jsonResponse.ValueKind == JsonValueKind.Object)
{
errorCode = jsonResponse.TryGetProperty("code", out JsonElement jsonErrorCode) ? jsonErrorCode.GetInt32() : null;
errorMessage = jsonResponse.TryGetProperty("message", out JsonElement jsonErrorMessage) ? jsonErrorMessage.GetString() : errorCode.HasValue ? $"Error code: {errorCode}" : errorMessage;
if (jsonResponse.TryGetProperty("code", out JsonElement codeJsonProperty)) errorCode = codeJsonProperty.GetInt32();
else if (jsonResponse.TryGetProperty("errorCode", out JsonElement errorCodeJsonProperty)) errorCode = int.Parse(errorCodeJsonProperty.GetString());

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

if (jsonResponse.TryGetProperty("errors", out JsonElement jsonErrorDetails))
{
var errorDetails = string.Join(
Expand Down

0 comments on commit aa6e621

Please sign in to comment.