refactor(ReadHistoryQuery): update to not throw exception.
- update controller to throw NotFound if the list is empty
This commit is contained in:
@@ -33,7 +33,7 @@ public static class TaskExtensions
|
||||
/// <param name="factory">Exception provider</param>
|
||||
/// <returns>The awaited collection if it is not <c>null</c> or empty.</returns>
|
||||
/// <exception cref="NotFoundException">Thrown if the result is <c>null</c> or empty.</exception>
|
||||
public static async Task<IEnumerable<T>> ThrowIfNull<T, TException>(this Task<IEnumerable<T>> task, Func<TException> factory) where TException : Exception
|
||||
public static async Task<IEnumerable<T>> ThrowIfEmpty<T, TException>(this Task<IEnumerable<T>> task, Func<TException> factory) where TException : Exception
|
||||
{
|
||||
var result = await task;
|
||||
return result?.Any() ?? false ? result : throw factory();
|
||||
|
||||
@@ -16,6 +16,4 @@ public record ReadHistoryQuery(
|
||||
[Required]
|
||||
int EnvelopeId,
|
||||
Constants.EnvelopeStatus? Status = null,
|
||||
bool? OnlyLast = true) : IRequest<IEnumerable<EnvelopeHistoryDto>>
|
||||
{
|
||||
};
|
||||
bool? OnlyLast = true) : IRequest<IEnumerable<EnvelopeHistoryDto>>;
|
||||
@@ -42,10 +42,6 @@ public class ReadHistoryQueryHandler : IRequestHandler<ReadHistoryQuery, IEnumer
|
||||
query = query.Where(h => h.Status == request.Status);
|
||||
|
||||
var hists = await query.ToListAsync(cancel);
|
||||
|
||||
if (hists.Count == 0)
|
||||
return _mapper.Map<IEnumerable<EnvelopeHistoryDto>>(hists);
|
||||
|
||||
throw new NotFoundException();
|
||||
return _mapper.Map<IEnumerable<EnvelopeHistoryDto>>(hists);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user