Skip to content

Commit 6426bc6

Browse files
Replace generic exception in PRI workflow to give better user messages on expected failures. (#952)
1 parent 2c80719 commit 6426bc6

3 files changed

Lines changed: 34 additions & 3 deletions

File tree

src/Application/Features/PRIs/EventHandlers/PreventCompletionOfTaskWithoutRelease.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using Cfo.Cats.Domain.Events;
2-
2+
using Cfo.Cats.Domain.Common.Exceptions;
33
namespace Cfo.Cats.Application.Features.PRIs.EventHandlers;
44

55
internal class PreventCompletionOfTaskWithoutRelease(IUnitOfWork unitOfWork) : INotificationHandler<ObjectiveTaskCompletedDomainEvent>
66
{
7+
8+
// TODO: Replace this with a business rule?
79
public async Task Handle(ObjectiveTaskCompletedDomainEvent notification, CancellationToken cancellationToken)
810
{
911
if (notification.Item is { IsMandatory: true, Index: 2 } && notification.Item.CompletedStatus == CompletionStatus.Done)
@@ -20,7 +22,7 @@ public async Task Handle(ObjectiveTaskCompletedDomainEvent notification, Cancell
2022

2123
if (pri.ActualReleaseDate is null)
2224
{
23-
throw new ApplicationException("Cannot accept this task as the actual release date is missing from the PRI");
25+
throw new PriMissingActualReleaseDateException();
2426
}
2527

2628
// Has the participant been in the expected release region after the PRI was created?
@@ -32,7 +34,7 @@ public async Task Handle(ObjectiveTaskCompletedDomainEvent notification, Cancell
3234

3335
if (hasBeenReleasedToLocation is false)
3436
{
35-
throw new ApplicationException("Cannot accept this task as notice of the participants release to the expected release region has not yet been received.");
37+
throw new PriNeverBeenInLocationException();
3638
}
3739
}
3840
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace Cfo.Cats.Domain.Common.Exceptions;
2+
3+
public class PriMissingActualReleaseDateException : DomainException
4+
{
5+
/// <summary>
6+
/// Exception that is raised if an attempt is made to close a PRI objective
7+
/// when the actual release date has not been set.
8+
/// </summary>
9+
public PriMissingActualReleaseDateException()
10+
: base("Task cannot be completed until the actual release date is set.")
11+
{
12+
13+
}
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace Cfo.Cats.Domain.Common.Exceptions;
2+
3+
public class PriNeverBeenInLocationException : DomainException
4+
{
5+
/// <summary>
6+
/// Exception that is raised if an attempt is made to close a PRI objective
7+
/// when the participant has not been recorded as being in the specified release
8+
/// region.
9+
/// </summary>
10+
public PriNeverBeenInLocationException()
11+
: base("Task cannot be completed as notice of the participant's transfer to the expected release region has not yet been received.")
12+
{
13+
14+
}
15+
}

0 commit comments

Comments
 (0)