Skip to content

Commit

Permalink
Fix unable to delete edge model when thing type doesn't exists
Browse files Browse the repository at this point in the history
  • Loading branch information
kbeaugrand committed Jun 25, 2023
1 parent 331f3e7 commit 8cede48
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/IoTHub.Portal.Infrastructure/Services/AWS/AwsConfigService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ namespace IoTHub.Portal.Infrastructure.Services.AWS
using Amazon.GreengrassV2.Model;
using Amazon.IoT;
using Amazon.IoT.Model;
using Amazon.Runtime.Internal.Util;
using AutoMapper;
using IoTHub.Portal.Application.Services;
using IoTHub.Portal.Domain;
using IoTHub.Portal.Domain.Exceptions;
using IoTHub.Portal.Domain.Repositories;
using IoTHub.Portal.Models.v10;
using IoTHub.Portal.Shared.Models.v10;
using Microsoft.Extensions.Logging;
using Configuration = Microsoft.Azure.Devices.Configuration;

public class AwsConfigService : IConfigService
Expand All @@ -29,19 +31,23 @@ public class AwsConfigService : IConfigService
private readonly ConfigHandler config;
private readonly IMapper mapper;

private readonly ILogger<AwsConfigService> logger;

public AwsConfigService(
IAmazonGreengrassV2 greengrass,
IAmazonIoT iot,
IMapper mapper,
IUnitOfWork unitOfWork,
IEdgeDeviceModelRepository edgeModelRepository,
ILogger<AwsConfigService> logger,
ConfigHandler config)
{
this.greengrass = greengrass;
this.iotClient = iot;
this.mapper = mapper;
this.unitOfWork = unitOfWork;
this.edgeModelRepository = edgeModelRepository;
this.logger = logger;
this.config = config;
}

Expand Down Expand Up @@ -276,6 +282,10 @@ private async Task DeprecateDeploymentThingType(string modelId)
ThingTypeName = deployment.DeploymentName
});
}
catch (Amazon.IoT.Model.ResourceNotFoundException e)
{
this.logger.LogWarning($"Failed to depreciate thing type {deployment.DeploymentName} since it does'nt exist.");
}
catch (AmazonIoTException e)
{
throw new InternalServerErrorException($"Unable to deprecate the Thing type associated with {deployment.DeploymentName} due to an error in the Amazon IoT API", e);
Expand Down

0 comments on commit 8cede48

Please sign in to comment.