From 0421d3ae7ced1209d031a17b30c750ec542c56b8 Mon Sep 17 00:00:00 2001 From: Justin M <63619224+JustinMDotNet@users.noreply.github.com> Date: Wed, 25 Aug 2021 11:38:35 -0700 Subject: [PATCH] Added check if metadata is empty to throw error exception. (#1236) * Added check if metadata is empty to throw error exception. * Changed error message. * Changed error message to be displayed when invalid Workspace ID is provided for AzureMonitorLogs. --- .../DataSource/Monitor/MonitorClient.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Microsoft.Kusto.ServiceLayer/DataSource/Monitor/MonitorClient.cs b/src/Microsoft.Kusto.ServiceLayer/DataSource/Monitor/MonitorClient.cs index 54814cbb..300f095b 100644 --- a/src/Microsoft.Kusto.ServiceLayer/DataSource/Monitor/MonitorClient.cs +++ b/src/Microsoft.Kusto.ServiceLayer/DataSource/Monitor/MonitorClient.cs @@ -1,6 +1,7 @@ using System; using System.Net.Http; using System.Net.Http.Headers; +using System.Text; using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -52,6 +53,17 @@ namespace Microsoft.Kusto.ServiceLayer.DataSource.Monitor }; _metadata = JsonSerializer.Deserialize(results, options); + + if (_metadata?.Tables is null && _metadata?.Workspaces is null && _metadata?.TableGroups is null) + { + var errorMessage = JsonSerializer.Deserialize(results, options); + var builder = new StringBuilder(); + builder.AppendLine( + "The Log Analytics Workspace can not be reached. Please validate the Workspace ID, the correct tenant is selected, and that you have access to the workspace. "); + builder.AppendLine($"Error Message: {errorMessage?.Error?.Message}"); + throw new Exception(builder.ToString()); + } + return _metadata; }