Skip to content

Commit 0bbe5e3

Browse files
CDMS-851: 409 errors logged as warning instead of error (#135)
* CDMS-851: 409 errors logged as warning instead of error * CDMS-851: code formatting
1 parent 1850e13 commit 0bbe5e3

File tree

4 files changed

+174
-14
lines changed

4 files changed

+174
-14
lines changed

BtmsGateway.Test/Services/Routing/DecisionSenderTests.cs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,73 @@ public async Task When_sending_decision_and_comparer_returns_unsuccessful_status
334334
)
335335
);
336336
thrownException.Message.Should().Be("mrn-123 Failed to send Decision to Decision Comparer.");
337+
338+
_logger
339+
.Received(1)
340+
.Error(
341+
Arg.Any<string>(),
342+
Arg.Any<string>(),
343+
Arg.Any<string>(),
344+
Arg.Any<HttpStatusCode>(),
345+
Arg.Any<string>()
346+
);
347+
_logger
348+
.DidNotReceiveWithAnyArgs()
349+
.Warning(
350+
Arg.Any<string>(),
351+
Arg.Any<string>(),
352+
Arg.Any<string>(),
353+
Arg.Any<HttpStatusCode>(),
354+
Arg.Any<string>()
355+
);
356+
}
357+
358+
[Fact]
359+
public async Task When_sending_decision_and_comparer_returns_conflict_status_response_Then_exception_is_thrown()
360+
{
361+
var comparerResponse = new HttpResponseMessage(HttpStatusCode.Conflict);
362+
363+
_apiSender
364+
.SendToDecisionComparerAsync(
365+
Arg.Any<string>(),
366+
Arg.Any<string>(),
367+
Arg.Any<string>(),
368+
Arg.Any<CancellationToken>(),
369+
Arg.Any<IHeaderDictionary>()
370+
)
371+
.Returns(comparerResponse);
372+
373+
var thrownException = await Assert.ThrowsAsync<DecisionComparisonException>(() =>
374+
_decisionSender.SendDecisionAsync(
375+
"mrn-123",
376+
"<AlvsDecisionNotification />",
377+
MessagingConstants.MessageSource.Alvs,
378+
new RoutingResult(),
379+
new HeaderDictionary(),
380+
"external-correlation-id",
381+
CancellationToken.None
382+
)
383+
);
384+
thrownException.Message.Should().Be("mrn-123 Failed to send Decision to Decision Comparer.");
385+
386+
_logger
387+
.Received(1)
388+
.Warning(
389+
Arg.Any<string>(),
390+
Arg.Any<string>(),
391+
Arg.Any<string>(),
392+
Arg.Any<HttpStatusCode>(),
393+
Arg.Any<string>()
394+
);
395+
_logger
396+
.DidNotReceiveWithAnyArgs()
397+
.Error(
398+
Arg.Any<string>(),
399+
Arg.Any<string>(),
400+
Arg.Any<string>(),
401+
Arg.Any<HttpStatusCode>(),
402+
Arg.Any<string>()
403+
);
337404
}
338405

339406
[Fact]

BtmsGateway.Test/Services/Routing/ErrorNotificationSenderTests.cs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,71 @@ public async Task When_sending_error_notification_and_comparer_returns_unsuccess
446446
)
447447
);
448448
thrownException.Message.Should().Be("mrn-123 Failed to send Error Notification to Decision Comparer.");
449+
450+
_logger
451+
.Received(1)
452+
.Error(
453+
Arg.Any<string>(),
454+
Arg.Any<string>(),
455+
Arg.Any<string>(),
456+
Arg.Any<HttpStatusCode>(),
457+
Arg.Any<string>()
458+
);
459+
_logger
460+
.DidNotReceiveWithAnyArgs()
461+
.Warning(
462+
Arg.Any<string>(),
463+
Arg.Any<string>(),
464+
Arg.Any<string>(),
465+
Arg.Any<HttpStatusCode>(),
466+
Arg.Any<string>()
467+
);
468+
}
469+
470+
[Fact]
471+
public async Task When_sending_error_notification_and_comparer_returns_conflict_status_response_Then_exception_is_thrown()
472+
{
473+
var comparerResponse = new HttpResponseMessage(HttpStatusCode.Conflict);
474+
475+
_apiSender
476+
.SendToDecisionComparerAsync(
477+
Arg.Any<string>(),
478+
Arg.Any<string>(),
479+
Arg.Any<string>(),
480+
Arg.Any<CancellationToken>(),
481+
Arg.Any<IHeaderDictionary>()
482+
)
483+
.Returns(comparerResponse);
484+
485+
var thrownException = await Assert.ThrowsAsync<DecisionComparisonException>(() =>
486+
_errorNotificationSender.SendErrorNotificationAsync(
487+
"mrn-123",
488+
"<HMRCErrorNotification />",
489+
MessagingConstants.MessageSource.Btms,
490+
new RoutingResult(),
491+
cancellationToken: CancellationToken.None
492+
)
493+
);
494+
thrownException.Message.Should().Be("mrn-123 Failed to send Error Notification to Decision Comparer.");
495+
496+
_logger
497+
.Received(1)
498+
.Warning(
499+
Arg.Any<string>(),
500+
Arg.Any<string>(),
501+
Arg.Any<string>(),
502+
Arg.Any<HttpStatusCode>(),
503+
Arg.Any<string>()
504+
);
505+
_logger
506+
.DidNotReceiveWithAnyArgs()
507+
.Error(
508+
Arg.Any<string>(),
509+
Arg.Any<string>(),
510+
Arg.Any<string>(),
511+
Arg.Any<HttpStatusCode>(),
512+
Arg.Any<string>()
513+
);
449514
}
450515

451516
// [Fact]

BtmsGateway/Services/Routing/DecisionSender.cs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,27 @@ public async Task<RoutingResult> SendDecisionAsync(
8686

8787
if (!comparerResponse.StatusCode.IsSuccessStatusCode())
8888
{
89-
_logger.Error(
90-
"{CorrelationId} {MRN} Failed to send Decision to Decision Comparer: Status Code: {ComparerResponseStatusCode}, Reason: {ComparerResponseReason}.",
91-
correlationId,
92-
mrn,
93-
comparerResponse.StatusCode,
94-
comparerResponse.ReasonPhrase
95-
);
89+
if (comparerResponse.StatusCode == HttpStatusCode.Conflict)
90+
{
91+
_logger.Warning(
92+
"{CorrelationId} {MRN} Failed to send Decision to Decision Comparer: Status Code: {ComparerResponseStatusCode}, Reason: {ComparerResponseReason}.",
93+
correlationId,
94+
mrn,
95+
comparerResponse.StatusCode,
96+
comparerResponse.ReasonPhrase
97+
);
98+
}
99+
else
100+
{
101+
_logger.Error(
102+
"{CorrelationId} {MRN} Failed to send Decision to Decision Comparer: Status Code: {ComparerResponseStatusCode}, Reason: {ComparerResponseReason}.",
103+
correlationId,
104+
mrn,
105+
comparerResponse.StatusCode,
106+
comparerResponse.ReasonPhrase
107+
);
108+
}
109+
96110
throw new DecisionComparisonException($"{mrn} Failed to send Decision to Decision Comparer.");
97111
}
98112

BtmsGateway/Services/Routing/ErrorNotificationSender.cs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,27 @@ public async Task<RoutingResult> SendErrorNotificationAsync(
9393

9494
if (!comparerResponse.StatusCode.IsSuccessStatusCode())
9595
{
96-
_logger.Error(
97-
"{CorrelationId} {MRN} Failed to send Error Notification to Decision Comparer: Status Code: {ComparerResponseStatusCode}, Reason: {ComparerResponseReason}.",
98-
correlationId,
99-
mrn,
100-
comparerResponse.StatusCode,
101-
comparerResponse.ReasonPhrase
102-
);
96+
if (comparerResponse.StatusCode == HttpStatusCode.Conflict)
97+
{
98+
_logger.Warning(
99+
"{CorrelationId} {MRN} Failed to send Error Notification to Decision Comparer: Status Code: {ComparerResponseStatusCode}, Reason: {ComparerResponseReason}.",
100+
correlationId,
101+
mrn,
102+
comparerResponse.StatusCode,
103+
comparerResponse.ReasonPhrase
104+
);
105+
}
106+
else
107+
{
108+
_logger.Error(
109+
"{CorrelationId} {MRN} Failed to send Error Notification to Decision Comparer: Status Code: {ComparerResponseStatusCode}, Reason: {ComparerResponseReason}.",
110+
correlationId,
111+
mrn,
112+
comparerResponse.StatusCode,
113+
comparerResponse.ReasonPhrase
114+
);
115+
}
116+
103117
throw new DecisionComparisonException($"{mrn} Failed to send Error Notification to Decision Comparer.");
104118
}
105119

0 commit comments

Comments
 (0)