Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,14 @@ services:
class: Marein\Nchan\HttpAdapter\Psr18ClientAdapter
arguments: ['@psr18.http_client', '@psr18.http_client', '@psr18.http_client']

# Custom exception listener for the gaming domain.
# Lower priority so that the profiler is respected.
# todo: This can be removed as soon as https://github.com/marein/php-gaming-website/issues/34 is done.
Gaming\Common\ExceptionHandling\GamingExceptionListener:
tags: [{ name: kernel.event_listener, event: kernel.exception, priority: -100 }]

# Lower priority so that the profiler is respected.
Gaming\Common\Domain\Integration\RespondWithViolationsAsJsonOnKernelExceptionListener:
arguments: [[], '@translator']
tags: [{ name: kernel.event_listener, event: kernel.exception, priority: -99 }]
tags: [{ name: kernel.event_listener, event: kernel.exception, priority: -100 }]

Gaming\WebInterface\Infrastructure\Symfony\HandleFragmentExceptions:
arguments: ['#^/_fragment#']
tags: [{ name: kernel.event_listener, event: kernel.exception, priority: -98 }]
tags: [{ name: kernel.event_listener, event: kernel.exception, priority: -99 }]

Gaming\WebInterface\Infrastructure\Symfony\NotifyBrowserAboutLogin:
tags:
Expand Down
2 changes: 1 addition & 1 deletion src/Chat/Application/ChatId.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static function fromString(string $chatId): ChatId
{
try {
return new self(Uuid::fromRfc4122($chatId));
} catch (Exception $exception) {
} catch (Exception) {
// This occurs if the given string is an invalid Uuid, hence an invalid ChatId.
// Throw exception, that the chat can't be found.
throw new ChatNotFoundException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,35 @@ final class RespondWithViolationsAsJsonOnKernelExceptionListener
*/
public function __construct(
private readonly array $identifierToStatusCode,
private readonly TranslatorInterface $translator
private readonly TranslatorInterface $translator,
private readonly string $defaultIdentifier = 'an_error_occurred'
) {
}

public function onKernelException(ExceptionEvent $event): void
{
$exception = $event->getThrowable();

if (!($exception instanceof DomainException)) {
return;
}

if ($event->getRequest()->getRequestFormat() !== 'json') {
return;
}

$exception = $event->getThrowable();

$event->setResponse(
new JsonResponse(
[
'message' => $this->extractMessage($exception->violations),
'violations' => $this->transformViolationsToArray($exception->violations)
],
$this->statusCodeFromFirstMatchingViolationName($exception)
)
match (true) {
$exception instanceof DomainException => new JsonResponse(
[
'message' => $this->extractMessage($exception->violations),
'violations' => $this->transformViolationsToArray($exception->violations)
],
$this->statusCodeFromFirstMatchingViolationName($exception)
),
default => new JsonResponse(
[
'message' => $this->translator->trans($this->defaultIdentifier)
],
Response::HTTP_INTERNAL_SERVER_ERROR
)
}
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ConnectFour/Domain/Game/GameId.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static function fromString(string $gameId): GameId
{
try {
return new self(Uuid::fromRfc4122($gameId));
} catch (Exception $exception) {
} catch (Exception) {
// This occurs if the given string is an invalid Uuid, hence an invalid GameId.
// Throw exception, that the game can't be found.
throw new GameNotFoundException();
Expand Down
8 changes: 4 additions & 4 deletions src/Identity/Domain/Model/Account/AccountId.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public static function fromString(string $accountId): AccountId
{
try {
return new self(Uuid::fromRfc4122($accountId));
} catch (Exception $exception) {
throw new AccountNotFoundException(previous: $exception);
} catch (Exception) {
throw new AccountNotFoundException();
}
}

Expand All @@ -42,8 +42,8 @@ public static function forUserId(string $userId): AccountId
{
try {
return new self(Uuid::fromRfc4122($userId));
} catch (Exception $exception) {
throw new UserNotFoundException(previous: $exception);
} catch (Exception) {
throw new UserNotFoundException();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Gaming\Identity\Domain\Model\Account\Exception;

use Exception;
use Gaming\Common\Domain\Exception\DomainException;

class AccountException extends Exception
class AccountException extends DomainException
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

namespace Gaming\Identity\Domain\Model\Account\Exception;

use Gaming\Common\Domain\Exception\Violation;
use Gaming\Common\Domain\Exception\Violations;

final class AccountNotFoundException extends AccountException
{
public function __construct()
{
parent::__construct(new Violations(new Violation('account_not_found')));
}
}
4 changes: 2 additions & 2 deletions src/Identity/Domain/Model/Bot/Exception/BotException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Gaming\Identity\Domain\Model\Bot\Exception;

use Exception;
use Gaming\Common\Domain\Exception\DomainException;

class BotException extends Exception
class BotException extends DomainException
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

namespace Gaming\Identity\Domain\Model\Bot\Exception;

use Gaming\Common\Domain\Exception\Violation;
use Gaming\Common\Domain\Exception\Violations;

final class BotNotFoundException extends BotException
{
public function __construct()
{
parent::__construct(new Violations(new Violation('bot_not_found')));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

namespace Gaming\Identity\Domain\Model\Bot\Exception;

use Gaming\Common\Domain\Exception\Violation;
use Gaming\Common\Domain\Exception\Violations;

final class UsernameAlreadyExistsException extends BotException
{
public function __construct()
{
parent::__construct(new Violations(new Violation('username_already_exists')));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

namespace Gaming\Identity\Domain\Model\User\Exception;

use Gaming\Common\Domain\Exception\Violation;
use Gaming\Common\Domain\Exception\Violations;

final class EmailAlreadyExistsException extends UserException
{
public function __construct()
{
parent::__construct(new Violations(new Violation('email_already_exists')));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

namespace Gaming\Identity\Domain\Model\User\Exception;

use Gaming\Common\Domain\Exception\Violation;
use Gaming\Common\Domain\Exception\Violations;

class UserAlreadySignedUpException extends UserException
{
public function __construct()
{
parent::__construct(new Violations(new Violation('user_already_signed_up')));
}
}
4 changes: 2 additions & 2 deletions src/Identity/Domain/Model/User/Exception/UserException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Gaming\Identity\Domain\Model\User\Exception;

use Exception;
use Gaming\Common\Domain\Exception\DomainException;

class UserException extends Exception
class UserException extends DomainException
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

namespace Gaming\Identity\Domain\Model\User\Exception;

use Gaming\Common\Domain\Exception\Violation;
use Gaming\Common\Domain\Exception\Violations;

class UserNotFoundException extends UserException
{
public function __construct()
{
parent::__construct(new Violations(new Violation('user_not_found')));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

namespace Gaming\Identity\Domain\Model\User\Exception;

use Gaming\Common\Domain\Exception\Violation;
use Gaming\Common\Domain\Exception\Violations;

final class UsernameAlreadyExistsException extends UserException
{
public function __construct()
{
parent::__construct(new Violations(new Violation('username_already_exists')));
}
}
4 changes: 2 additions & 2 deletions src/Memory/Domain/Model/Game/Exception/GameException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Gaming\Memory\Domain\Model\Game\Exception;

use Exception;
use Gaming\Common\Domain\Exception\DomainException;

class GameException extends Exception
class GameException extends DomainException
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

namespace Gaming\Memory\Domain\Model\Game\Exception;

use Gaming\Common\Domain\Exception\Violation;
use Gaming\Common\Domain\Exception\Violations;

final class GameNotFoundException extends GameException
{
public function __construct()
{
parent::__construct(new Violations(new Violation('game_not_found')));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

namespace Gaming\Memory\Domain\Model\Game\Exception;

use Gaming\Common\Domain\Exception\Violation;
use Gaming\Common\Domain\Exception\Violations;

final class GameNotOpenException extends GameException
{
public function __construct()
{
parent::__construct(new Violations(new Violation('game_not_open')));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

namespace Gaming\Memory\Domain\Model\Game\Exception;

use Gaming\Common\Domain\Exception\Violation;
use Gaming\Common\Domain\Exception\Violations;

final class PlayerAlreadyJoinedException extends GameException
{
public function __construct()
{
parent::__construct(new Violations(new Violation('player_already_joined')));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

namespace Gaming\Memory\Domain\Model\Game\Exception;

use Gaming\Common\Domain\Exception\Violation;
use Gaming\Common\Domain\Exception\Violations;

final class PlayerNotAllowedToStartGameException extends GameException
{
public function __construct()
{
parent::__construct(new Violations(new Violation('player_not_allowed_to_start_game')));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

namespace Gaming\Memory\Domain\Model\Game\Exception;

use Gaming\Common\Domain\Exception\Violation;
use Gaming\Common\Domain\Exception\Violations;

final class PlayerNotJoinedException extends GameException
{
public function __construct()
{
parent::__construct(new Violations(new Violation('player_not_joined')));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

namespace Gaming\Memory\Domain\Model\Game\Exception;

use Gaming\Common\Domain\Exception\Violation;
use Gaming\Common\Domain\Exception\Violations;

final class PlayerPoolIsEmptyException extends GameException
{
public function __construct()
{
parent::__construct(new Violations(new Violation('player_pool_is_empty')));
}
}