Skip to content

Commit

Permalink
Improve AWS Exception
Browse files Browse the repository at this point in the history
  • Loading branch information
ssgueye2 committed Jun 16, 2023
1 parent 0366710 commit 8d41fbc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,20 @@ public override async Task DeleteDevice(string deviceId)
ThingName = device.Name
});

foreach (var principal in principals.Principals)
try
{
try
foreach (var principal in principals.Principals)
{
var detachPrincipal = await this.amazonIoTClient.DetachThingPrincipalAsync(new DetachThingPrincipalRequest
{
Principal = principal,
ThingName = device.Name
});
}
catch (AmazonIoTException e)
{
this.logger.LogWarning("Can not detach Thing principal because it doesn't exist in AWS IoT", e);
}
}
catch (AmazonIoTException e)
{
this.logger.LogWarning("Can not detach Thing principal because it doesn't exist in AWS IoT", e);
}

try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ public async Task DeleteDeviceShouldThrowInternalServerErrorIfHttpStatusCodeIsNo
}

[Test]
public async Task DeleteDeviceShouldThrowInternalServerErrorIfHttpStatusCodeIsNotOKForDetachThingPrincipal()
public async Task DeleteDeviceShouldThrowExceptionIfFailedWhenDetachThingPrincipal()
{
// Arrange
var deviceDto = new DeviceDetails
Expand All @@ -494,10 +494,12 @@ public async Task DeleteDeviceShouldThrowInternalServerErrorIfHttpStatusCodeIsNo
Fixture.Create<string>()
},
HttpStatusCode = HttpStatusCode.OK
}); ;
});

_ = this.mockAmazonIotClient.Setup(service => service.DetachThingPrincipalAsync(It.IsAny<DetachThingPrincipalRequest>(), It.IsAny<CancellationToken>()))
.ThrowsAsync(new AmazonIoTException(It.IsAny<string>()));
_ = this.mockAmazonIotClient.Setup(service => service.DeleteThingAsync(It.IsAny<DeleteThingRequest>(), It.IsAny<CancellationToken>()))
.ThrowsAsync(new AmazonIoTException(It.IsAny<string>()));

_ = this.mockDeviceRepository.Setup(repository => repository.GetByIdAsync(deviceDto.DeviceID, d => d.Tags, d => d.Labels))
.ReturnsAsync(device);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,9 @@ public async Task WhenThingNotExistsAndCoreReturnBadRequestDeviceDeleteShouldPas
.ThrowsAsync(new Amazon.IoT.Model.ResourceNotFoundException(Fixture.Create<string>()));

// Act
var act = () => this.externalDeviceService.DeleteDevice(deviceId);
await this.externalDeviceService.DeleteDevice(deviceId);

// Assert
_ = await act.Should().ThrowAsync<Portal.Domain.Exceptions.InternalServerErrorException>();

this.MockRepository.VerifyAll();
}

Expand Down

0 comments on commit 8d41fbc

Please sign in to comment.