Work with DatabaseException in UserDeletedRepository

This commit is contained in:
Art4 2025-04-15 14:48:01 +00:00
parent 2879db12dc
commit e4a93fc9c7
5 changed files with 20 additions and 18 deletions

View file

@ -28,14 +28,16 @@ final class UserDeletedRepository
/**
* Insert a deleted user by username.
*
* @throws \Exception If the username could not be inserted
* @throws DatabaseException If the username could not be inserted
*/
public function insertByUsername(string $username): void
{
$result = $this->database->insert('userd', ['username' => $username]);
$this->database->throwExceptionsOnErrors(true);
if ($result === false) {
throw new Exception(sprintf('Error while inserting username `%s` as deleted user.', $username));
try {
$this->database->insert('userd', ['username' => $username]);
} finally {
$this->database->throwExceptionsOnErrors(false);
}
}