Add StandardException handling in StandardMethods
This commit is contained in:
parent
e610cb6e1e
commit
292c6ac042
1 changed files with 7 additions and 2 deletions
|
@ -4,6 +4,7 @@ namespace Socialbox\Enums;
|
||||||
|
|
||||||
use Socialbox\Classes\StandardMethods\CreateSession;
|
use Socialbox\Classes\StandardMethods\CreateSession;
|
||||||
use Socialbox\Classes\StandardMethods\Ping;
|
use Socialbox\Classes\StandardMethods\Ping;
|
||||||
|
use Socialbox\Exceptions\StandardException;
|
||||||
use Socialbox\Interfaces\SerializableInterface;
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
use Socialbox\Objects\ClientRequest;
|
use Socialbox\Objects\ClientRequest;
|
||||||
use Socialbox\Objects\RpcRequest;
|
use Socialbox\Objects\RpcRequest;
|
||||||
|
@ -13,14 +14,18 @@ enum StandardMethods : string
|
||||||
case PING = 'ping';
|
case PING = 'ping';
|
||||||
case CREATE_SESSION = 'create_session';
|
case CREATE_SESSION = 'create_session';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ClientRequest $request
|
||||||
|
* @param RpcRequest $rpcRequest
|
||||||
|
* @return SerializableInterface|null
|
||||||
|
* @throws StandardException
|
||||||
|
*/
|
||||||
public function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
public function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
||||||
{
|
{
|
||||||
return match ($this)
|
return match ($this)
|
||||||
{
|
{
|
||||||
self::PING => Ping::execute($request, $rpcRequest),
|
self::PING => Ping::execute($request, $rpcRequest),
|
||||||
self::CREATE_SESSION => CreateSession::execute($request, $rpcRequest),
|
self::CREATE_SESSION => CreateSession::execute($request, $rpcRequest),
|
||||||
|
|
||||||
default => $rpcRequest->produceError(StandardError::RPC_METHOD_NOT_FOUND, sprintf('The method %s is not handled by the server', $this->value)),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue