Skip to content

Commit

Permalink
Catching a user not found exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduard Keilholz committed Feb 16, 2024
1 parent 44c3558 commit 44eea31
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/Wam.Users/Repositories/UsersRepository.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Azure.Data.Tables;
using Azure;
using Azure.Data.Tables;
using HexMaster.RedisCache.Abstractions;
using Microsoft.Extensions.Options;
using Wam.Core.Configuration;
Expand Down Expand Up @@ -46,14 +47,20 @@ public async Task<User> Get(Guid userId, CancellationToken cancellationToken)

private async Task<UserEntity> GetFromTableStorage(Guid userId, CancellationToken cancellationToken)
{
var cloudResponse = await _tableClient.GetEntityAsync<UserEntity>(PartitionKey, userId.ToString(),
cancellationToken: cancellationToken);
try
{
var cloudResponse = await _tableClient.GetEntityAsync<UserEntity>(PartitionKey, userId.ToString(),
cancellationToken: cancellationToken);

if (cloudResponse.HasValue)
if (cloudResponse.HasValue)
{
return cloudResponse.Value;
}
}
catch (RequestFailedException ex) when (ex.Status == 404)
{
return cloudResponse.Value;
throw new WamUserException(UserErrorCode.UserNotFound, $"The user with GUID {userId} could not be found");
}

throw new WamUserException(UserErrorCode.UserNotFound, $"The user with GUID {userId} could not be found");
}

Expand Down

0 comments on commit 44eea31

Please # to comment.