[backend/core] Improve handling of UniqueConstraintExceptions in UserService.CreateUserAsync
This commit is contained in:
parent
9233e43b81
commit
030aef6c8d
1 changed files with 8 additions and 2 deletions
|
@ -206,9 +206,9 @@ public class UserService(
|
|||
});
|
||||
return user;
|
||||
}
|
||||
catch (UniqueConstraintException)
|
||||
catch (UniqueConstraintException e) when (e.ConstraintProperties is [nameof(User.Uri)])
|
||||
{
|
||||
logger.LogDebug("Encountered UniqueConstraintException while creating user {uri}, attempting to refetch...",
|
||||
logger.LogError("Encountered UniqueConstraintException while creating user {uri}, attempting to refetch...",
|
||||
user.Uri);
|
||||
// another thread got there first, so we need to return the existing user
|
||||
var res = await db.Users
|
||||
|
@ -226,6 +226,12 @@ public class UserService(
|
|||
|
||||
return res;
|
||||
}
|
||||
catch (UniqueConstraintException e)
|
||||
{
|
||||
logger.LogError("Failed to insert user: Unable to satisfy unique constraint: {constraint}",
|
||||
e.ConstraintName);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<User> UpdateUserAsync(string id)
|
||||
|
|
Loading…
Add table
Reference in a new issue