Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #142 connection string give an error when enrollment group doesn't exist #159

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions src/AzureIoTHub.Portal/Client/Pages/Gateways/Detail.razor
Original file line number Diff line number Diff line change
Expand Up @@ -269,16 +269,30 @@ else

public async Task ShowConnectionString()
{
gateway.SymmetricKey = await this.Http.GetStringAsync($"api/Gateways/{gateway.DeviceId}/ConnectionString");
try
{
gateway.SymmetricKey = await this.Http.GetStringAsync($"api/Gateways/{gateway.DeviceId}/ConnectionString");

var parameter = new DialogParameters();
var parameter = new DialogParameters();

parameter.Add(nameof(Gateway.DeviceId), gateway.DeviceId);
parameter.Add(nameof(Gateway.EndPoint), gateway.EndPoint);
parameter.Add(nameof(Gateway.SymmetricKey), gateway.SymmetricKey);
parameter.Add(nameof(Gateway.DeviceId), gateway.DeviceId);
parameter.Add(nameof(Gateway.EndPoint), gateway.EndPoint);
parameter.Add(nameof(Gateway.SymmetricKey), gateway.SymmetricKey);


DialogService.Show<ConnectionString>("ConnectionString gateway ", parameter);
DialogService.Show<ConnectionString>("ConnectionString gateway ", parameter);
}
catch ( HttpRequestException e)
{
if (e.StatusCode == System.Net.HttpStatusCode.NotFound)
{
Snackbar.Add("Cannot obtain the connection string <br> because the enrollment group does not exist.", Severity.Error);
}
else
{
Snackbar.Add($"Something went wrong.", Severity.Error);
}
}
}

public async Task ShowDeleteModal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace AzureIoTHub.Portal.Server.Controllers
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Devices;
using Microsoft.Azure.Devices.Common.Exceptions;
using Microsoft.Azure.Devices.Provisioning.Service;
using Microsoft.Azure.Devices.Shared;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -143,6 +144,10 @@ public async Task<IActionResult> GetSymmetricKey(string deviceId)
{
return this.Ok(await this.connectionStringManager.GetSymmetricKey(deviceId));
}
catch (ProvisioningServiceClientException e)
{
return this.NotFound(e.Message);
}
catch (Exception e)
{
return this.BadRequest(e.Message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace AzureIoTHub.Portal.Server.Managers
using System.Threading.Tasks;
using AzureIoTHub.Portal.Server.Helpers;
using AzureIoTHub.Portal.Server.Services;
using Microsoft.Azure.Devices.Provisioning.Service;

public class ConnectionStringManager : IConnectionStringManager
{
Expand All @@ -24,6 +25,10 @@ public async Task<string> GetSymmetricKey(string deviceId)

return DeviceHelper.RetrieveSymmetricKey(deviceId, attestationMechanism);
}
catch (ProvisioningServiceClientException)
{
throw new ProvisioningServiceClientException("The enrollment group does not exist.");
}
catch (System.Exception e)
{
throw new System.Exception(e.Message);
Expand Down