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.
This commit is contained in:
Justin M
2021-08-25 11:38:35 -07:00
committed by GitHub
parent c20af4f777
commit 0421d3ae7c

View File

@@ -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<WorkspaceResponse>(results, options);
if (_metadata?.Tables is null && _metadata?.Workspaces is null && _metadata?.TableGroups is null)
{
var errorMessage = JsonSerializer.Deserialize<ErrorResponse>(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;
}