Refactor EncryptionCloseChannel to simplify error handling and remove unused code
https://github.com/nosial/Socialbox-PHP/issues/19
This commit is contained in:
parent
d5e540789b
commit
5be20b0e70
1 changed files with 11 additions and 22 deletions
|
@ -4,13 +4,10 @@
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Socialbox\Abstracts\Method;
|
use Socialbox\Abstracts\Method;
|
||||||
use Socialbox\Classes\Logger;
|
|
||||||
use Socialbox\Classes\Validator;
|
|
||||||
use Socialbox\Enums\StandardError;
|
use Socialbox\Enums\StandardError;
|
||||||
use Socialbox\Enums\Status\EncryptionChannelStatus;
|
use Socialbox\Enums\Status\EncryptionChannelStatus;
|
||||||
use Socialbox\Exceptions\DatabaseOperationException;
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
use Socialbox\Exceptions\RpcException;
|
use Socialbox\Exceptions\RpcException;
|
||||||
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
|
||||||
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
||||||
use Socialbox\Exceptions\Standard\StandardRpcException;
|
use Socialbox\Exceptions\Standard\StandardRpcException;
|
||||||
use Socialbox\Interfaces\SerializableInterface;
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
|
@ -31,15 +28,18 @@
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('channel_uuid');
|
throw new MissingRpcArgumentException('channel_uuid');
|
||||||
}
|
}
|
||||||
elseif(!Validator::validateUuid($rpcRequest->getParameter('channel_uuid')))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('channel_uuid', 'The given channel uuid is not a valid UUID V4');
|
|
||||||
}
|
|
||||||
|
|
||||||
if($request->isExternal())
|
try
|
||||||
|
{
|
||||||
|
if ($request->isExternal())
|
||||||
{
|
{
|
||||||
return self::handleExternal($request, $rpcRequest);
|
return self::handleExternal($request, $rpcRequest);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (DatabaseOperationException $e)
|
||||||
|
{
|
||||||
|
throw new StandardRpcException('There was an error while handling the external request', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||||
|
}
|
||||||
|
|
||||||
return self::handleInternal($request, $rpcRequest);
|
return self::handleInternal($request, $rpcRequest);
|
||||||
}
|
}
|
||||||
|
@ -98,15 +98,6 @@
|
||||||
}
|
}
|
||||||
catch(Exception $e)
|
catch(Exception $e)
|
||||||
{
|
{
|
||||||
try
|
|
||||||
{
|
|
||||||
EncryptionChannelManager::declineChannel($rpcRequest->getParameter('channel_uuid'), true);
|
|
||||||
}
|
|
||||||
catch(DatabaseOperationException $e)
|
|
||||||
{
|
|
||||||
Logger::getLogger()->error('Error declining channel as server', $e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if($e instanceof RpcException)
|
if($e instanceof RpcException)
|
||||||
{
|
{
|
||||||
throw StandardRpcException::fromRpcException($e);
|
throw StandardRpcException::fromRpcException($e);
|
||||||
|
@ -145,13 +136,11 @@
|
||||||
{
|
{
|
||||||
return $rpcRequest->produceError(StandardError::NOT_FOUND, 'The requested encryption channel was not found');
|
return $rpcRequest->produceError(StandardError::NOT_FOUND, 'The requested encryption channel was not found');
|
||||||
}
|
}
|
||||||
|
elseif(!$encryptionChannel->isParticipant($request->getIdentifyAs()))
|
||||||
if(!$encryptionChannel->isParticipant($request->getIdentifyAs()))
|
|
||||||
{
|
{
|
||||||
return $rpcRequest->produceError(StandardError::UNAUTHORIZED, 'The requested encryption channel is not accessible');
|
return $rpcRequest->produceError(StandardError::UNAUTHORIZED, 'The requested encryption channel is not accessible');
|
||||||
}
|
}
|
||||||
|
elseif($encryptionChannel->getStatus() === EncryptionChannelStatus::CLOSED)
|
||||||
if($encryptionChannel->getStatus() === EncryptionChannelStatus::CLOSED)
|
|
||||||
{
|
{
|
||||||
return $rpcRequest->produceResponse(false);
|
return $rpcRequest->produceResponse(false);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue