From 1f55538ad4984b08060d26cf27b126724386a2ec Mon Sep 17 00:00:00 2001 From: netkas Date: Fri, 31 Jan 2025 12:56:45 -0500 Subject: [PATCH] Improved exception handling --- .../StandardMethods/Core/ResolvePeer.php | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Socialbox/Classes/StandardMethods/Core/ResolvePeer.php b/src/Socialbox/Classes/StandardMethods/Core/ResolvePeer.php index ce0f60c..5c728e2 100644 --- a/src/Socialbox/Classes/StandardMethods/Core/ResolvePeer.php +++ b/src/Socialbox/Classes/StandardMethods/Core/ResolvePeer.php @@ -2,11 +2,11 @@ namespace Socialbox\Classes\StandardMethods\Core; - use Exception; use InvalidArgumentException; use Socialbox\Abstracts\Method; use Socialbox\Enums\ReservedUsernames; use Socialbox\Enums\StandardError; + use Socialbox\Exceptions\DatabaseOperationException; use Socialbox\Exceptions\Standard\MissingRpcArgumentException; use Socialbox\Exceptions\Standard\StandardRpcException; use Socialbox\Interfaces\SerializableInterface; @@ -40,20 +40,20 @@ } // Check if host is making the request & the identifier is not empty - $identifyAs = null; - if($request->getPeer()->getUsername() == ReservedUsernames::HOST && $request->getIdentifyAs() != null) + try { - $identifyAs = $request->getIdentifyAs(); + $identifyAs = null; + if ($request->getPeer()->getUsername() == ReservedUsernames::HOST && $request->getIdentifyAs() != null) + { + $identifyAs = $request->getIdentifyAs(); + } + } + catch (DatabaseOperationException $e) + { + throw new StandardRpcException('Failed to retrieve peer information', StandardError::INTERNAL_SERVER_ERROR, $e); } // Resolve the peer using the server's peer resolver, this will resolve both internal peers and external peers - try - { - return $rpcRequest->produceResponse(Socialbox::resolvePeer($peerAddress, $identifyAs)); - } - catch(Exception $e) - { - throw new StandardRpcException(sprintf('There was an error while trying to resolve the peer %s: %s', $peerAddress, $e->getMessage()), StandardError::RESOLUTION_FAILED, $e); - } + return $rpcRequest->produceResponse(Socialbox::resolvePeer($peerAddress, $identifyAs)); } } \ No newline at end of file