Updated exception handling and logic in AddressBookDeleteContact
This commit is contained in:
parent
6e4c7bcc04
commit
4856dacb9d
1 changed files with 8 additions and 3 deletions
|
@ -6,6 +6,8 @@
|
|||
use Socialbox\Abstracts\Method;
|
||||
use Socialbox\Enums\StandardError;
|
||||
use Socialbox\Exceptions\DatabaseOperationException;
|
||||
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
||||
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
||||
use Socialbox\Exceptions\Standard\StandardException;
|
||||
use Socialbox\Interfaces\SerializableInterface;
|
||||
use Socialbox\Managers\ContactManager;
|
||||
|
@ -16,13 +18,16 @@
|
|||
class AddressBookDeleteContact extends Method
|
||||
{
|
||||
/**
|
||||
* Deletes a contact from the authenticated peer's address book, returns True if the contact was deleted
|
||||
* false if the contact does not exist.
|
||||
*
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
||||
{
|
||||
if(!$rpcRequest->containsParameter('peer'))
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, 'Missing required peer parameter');
|
||||
throw new MissingRpcArgumentException('peer');
|
||||
}
|
||||
|
||||
try
|
||||
|
@ -31,7 +36,7 @@
|
|||
}
|
||||
catch(InvalidArgumentException $e)
|
||||
{
|
||||
throw new StandardException('Invalid peer address', StandardError::RPC_INVALID_ARGUMENTS, $e);
|
||||
throw new InvalidRpcArgumentException('peer', $e->getMessage());
|
||||
}
|
||||
|
||||
try
|
||||
|
@ -40,7 +45,7 @@
|
|||
$peer = $request->getPeer();
|
||||
if(!ContactManager::isContact($peer, $address))
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::FORBIDDEN, 'Contact does not exist');
|
||||
return $rpcRequest->produceResponse(false);
|
||||
}
|
||||
|
||||
// Create the contact
|
||||
|
|
Loading…
Add table
Reference in a new issue