Skip to content

Commit db9308f

Browse files
feat: change transform error handling (#699)
* feat: change transformation exception handling * Update CreateCohortDistributionTests.cs
1 parent bb964f2 commit db9308f

File tree

4 files changed

+12
-16
lines changed

4 files changed

+12
-16
lines changed

application/CohortManager/src/Functions/CohortDistributionServices/CreateCohortDistribution/CreateCohortDistribution.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,7 @@ await HandleErrorResponseAsync($"Unable to add to cohort distribution. As partic
9191
// Transformation
9292
var transformedParticipant = await _CohortDistributionHelper.TransformParticipantAsync(serviceProvider, participantData);
9393
if (transformedParticipant == null)
94-
{
95-
await HandleErrorResponseAsync("The transformed participant returned null from the transform participant function", transformedParticipant, basicParticipantCsvRecord.FileName);
9694
return;
97-
}
9895

9996
// Add to cohort distribution table
10097
var cohortAddResponse = await AddCohortDistribution(transformedParticipant);

application/CohortManager/src/Functions/CohortDistributionServices/TransformDataService/TransformDataService.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ public async Task<HttpResponseData> RunAsync([HttpTrigger(AuthorizationLevel.Ano
9898
}
9999
return _createResponse.CreateHttpResponse(HttpStatusCode.Accepted, req, "");
100100
}
101+
catch (ArgumentException ex)
102+
{
103+
_logger.LogWarning(ex, "An error occurred during transformation");
104+
await _exceptionHandler.CreateSystemExceptionLogFromNhsNumber(ex, participant.NhsNumber, "", "", JsonSerializer.Serialize(participant));
105+
return _createResponse.CreateHttpResponse(HttpStatusCode.Accepted, req);
106+
}
101107
catch (TransformationException ex)
102108
{
103109
_logger.LogWarning(ex, "An error occurred during transformation");
@@ -203,7 +209,7 @@ private static CohortDistributionParticipant TransformAddress(CohortDistribution
203209
string.IsNullOrEmpty(requestParticipant.AddressLine5))
204210
{
205211
if (requestParticipant.Postcode != databaseParticipant.PostCode)
206-
throw new ArgumentException("Participant has an empty address and postcode does not match existing record");
212+
throw new TransformationException("Participant has an empty address and postcode does not match existing record");
207213

208214
requestParticipant.AddressLine1 = databaseParticipant.AddressLine1;
209215
requestParticipant.AddressLine2 = databaseParticipant.AddressLine2;

application/CohortManager/src/Functions/CohortDistributionServices/TransformDataService/TransformString.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,14 @@ private async Task<string> CheckParticipantCharactersAsync(string stringField)
6666
ParticipantUpdated = true;
6767
// Special characters that need to be handled separately
6868
if (stringField.Contains(@"\E\") || stringField.Contains(@"\T\"))
69-
{
70-
throw new ArgumentException("Participant contains illegal characters");
71-
}
69+
throw new ArgumentException($"Participant contains illegal characters");
7270

7371
var transformedField = await TransformCharactersAsync(stringField);
7472

7573
// Check to see if there are any unhandled invalid chars
7674
if (!Regex.IsMatch(transformedField, allowedCharacters, RegexOptions.None, matchTimeout))
77-
{
7875
throw new ArgumentException("Participant contains illegal characters");
79-
}
76+
8077
return transformedField;
8178
}
8279
}

tests/UnitTests/CohortDistributionTests/CreateCohortDistributionTests/CreateCohortDistributionTests.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public async Task RunAsync_AllocateServiceProviderToParticipantRequestFails_Retu
172172
}
173173

174174
[TestMethod]
175-
public async Task RunAsync_TransformDataServiceRequestFails_LogError()
175+
public async Task RunAsync_TransformDataServiceRequestFails_ReturnEarly()
176176
{
177177
// Arrange
178178
_cohortDistributionHelper
@@ -192,12 +192,8 @@ public async Task RunAsync_TransformDataServiceRequestFails_LogError()
192192
// Act
193193
await _sut.RunAsync(_requestBody);
194194

195-
_logger.Verify(x => x.Log(It.Is<LogLevel>(l => l == LogLevel.Error),
196-
It.IsAny<EventId>(),
197-
It.Is<It.IsAnyType>((v, t) => v.ToString().Contains("The transformed participant returned null from the transform participant function")),
198-
It.IsAny<Exception>(),
199-
It.IsAny<Func<It.IsAnyType, Exception, string>>()),
200-
Times.Once);
195+
// Assert
196+
_callFunction.Verify(x => x.SendPost("AddCohortDistributionURL", It.IsAny<string>()), Times.Never);
201197
}
202198

203199
[TestMethod]

0 commit comments

Comments
 (0)