Skip to content

Commit

Permalink
fix: handle the error that occurs when assigning a role
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosPavajeau committed Jul 25, 2021
1 parent cf5bd03 commit 6ffc045
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/Armory/Users/Application/Create/ArmoryUserCreator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Threading.Tasks;
using Armory.Users.Application.AddToRole;
using Armory.Users.Domain;
using Microsoft.AspNetCore.Identity;

namespace Armory.Users.Application.Create
{
Expand All @@ -26,11 +28,26 @@ public async Task<ArmoryUser> Create(string username, string email, string phone
throw new ArmoryUserNotCreated(result.Errors);
}

var roleResult = await _roleAggregator.AddToRole(user, roleName);
if (!roleResult.Succeeded)
try
{
throw new ArmoryUserNotCreated(roleResult.Errors);
var roleResult = await _roleAggregator.AddToRole(user, roleName);
if (!roleResult.Succeeded)
{
throw new ArmoryUserNotCreated(roleResult.Errors);
}
}
catch (InvalidOperationException e)
{
throw new ArmoryUserNotCreated(new[]
{
new IdentityError
{
Code = "RoleDoesNotExists",
Description = $"El rol '{roleName}' no existe."
}
});
}


return user;
}
Expand Down

0 comments on commit 6ffc045

Please sign in to comment.