From 55137a93f2bbafcd21a93df1f87b9e46a01c0cb3 Mon Sep 17 00:00:00 2001 From: netkas Date: Fri, 31 Jan 2025 13:15:34 -0500 Subject: [PATCH] Added better exception handling --- .../ServerDocuments/AcceptCommunityGuidelines.php | 12 ++++++++++-- .../ServerDocuments/AcceptPrivacyPolicy.php | 13 +++++++++++-- .../ServerDocuments/AcceptTermsOfService.php | 13 +++++++++++-- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/Socialbox/Classes/StandardMethods/ServerDocuments/AcceptCommunityGuidelines.php b/src/Socialbox/Classes/StandardMethods/ServerDocuments/AcceptCommunityGuidelines.php index bb40cd6..66dbb6e 100644 --- a/src/Socialbox/Classes/StandardMethods/ServerDocuments/AcceptCommunityGuidelines.php +++ b/src/Socialbox/Classes/StandardMethods/ServerDocuments/AcceptCommunityGuidelines.php @@ -6,6 +6,7 @@ use Socialbox\Enums\Flags\SessionFlags; use Socialbox\Enums\StandardError; use Socialbox\Exceptions\DatabaseOperationException; + use Socialbox\Exceptions\Standard\StandardRpcException; use Socialbox\Interfaces\SerializableInterface; use Socialbox\Managers\SessionManager; use Socialbox\Objects\ClientRequest; @@ -21,7 +22,14 @@ */ public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface { - $session = $request->getSession(); + try + { + $session = $request->getSession(); + } + catch (DatabaseOperationException $e) + { + throw new StandardRpcException('Failed to retrieve session', StandardError::INTERNAL_SERVER_ERROR, $e); + } if(!$session->flagExists(SessionFlags::VER_COMMUNITY_GUIDELINES)) { return $rpcRequest->produceError(StandardError::FORBIDDEN, 'Community guidelines has already been accepted'); @@ -34,7 +42,7 @@ } catch (DatabaseOperationException $e) { - return $rpcRequest->produceError(StandardError::INTERNAL_SERVER_ERROR, $e); + throw new StandardRpcException('Failed to update session flow', StandardError::INTERNAL_SERVER_ERROR, $e); } return $rpcRequest->produceResponse(true); diff --git a/src/Socialbox/Classes/StandardMethods/ServerDocuments/AcceptPrivacyPolicy.php b/src/Socialbox/Classes/StandardMethods/ServerDocuments/AcceptPrivacyPolicy.php index 72b1d86..681b06f 100644 --- a/src/Socialbox/Classes/StandardMethods/ServerDocuments/AcceptPrivacyPolicy.php +++ b/src/Socialbox/Classes/StandardMethods/ServerDocuments/AcceptPrivacyPolicy.php @@ -6,6 +6,7 @@ use Socialbox\Enums\Flags\SessionFlags; use Socialbox\Enums\StandardError; use Socialbox\Exceptions\DatabaseOperationException; + use Socialbox\Exceptions\Standard\StandardRpcException; use Socialbox\Interfaces\SerializableInterface; use Socialbox\Managers\SessionManager; use Socialbox\Objects\ClientRequest; @@ -20,7 +21,15 @@ */ public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface { - $session = $request->getSession(); + try + { + $session = $request->getSession(); + } + catch (DatabaseOperationException $e) + { + throw new StandardRpcException('Failed to retrieve session', StandardError::INTERNAL_SERVER_ERROR, $e); + } + if(!$session->flagExists(SessionFlags::VER_PRIVACY_POLICY)) { return $rpcRequest->produceError(StandardError::FORBIDDEN, 'Privacy policy has already been accepted'); @@ -33,7 +42,7 @@ } catch (DatabaseOperationException $e) { - return $rpcRequest->produceError(StandardError::INTERNAL_SERVER_ERROR, $e); + throw new StandardRpcException('Failed to update session flow', StandardError::INTERNAL_SERVER_ERROR, $e); } return $rpcRequest->produceResponse(true); diff --git a/src/Socialbox/Classes/StandardMethods/ServerDocuments/AcceptTermsOfService.php b/src/Socialbox/Classes/StandardMethods/ServerDocuments/AcceptTermsOfService.php index 369d427..3c11fa1 100644 --- a/src/Socialbox/Classes/StandardMethods/ServerDocuments/AcceptTermsOfService.php +++ b/src/Socialbox/Classes/StandardMethods/ServerDocuments/AcceptTermsOfService.php @@ -6,6 +6,7 @@ use Socialbox\Enums\Flags\SessionFlags; use Socialbox\Enums\StandardError; use Socialbox\Exceptions\DatabaseOperationException; + use Socialbox\Exceptions\Standard\StandardRpcException; use Socialbox\Interfaces\SerializableInterface; use Socialbox\Managers\SessionManager; use Socialbox\Objects\ClientRequest; @@ -20,7 +21,15 @@ */ public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface { - $session = $request->getSession(); + try + { + $session = $request->getSession(); + } + catch (DatabaseOperationException $e) + { + throw new StandardRpcException('Failed to retrieve session', StandardError::INTERNAL_SERVER_ERROR, $e); + } + if(!$session->flagExists(SessionFlags::VER_TERMS_OF_SERVICE)) { return $rpcRequest->produceError(StandardError::FORBIDDEN, 'Terms of service has already been accepted'); @@ -33,7 +42,7 @@ } catch (DatabaseOperationException $e) { - return $rpcRequest->produceError(StandardError::INTERNAL_SERVER_ERROR, $e); + throw new StandardRpcException('Failed to update session flow', StandardError::INTERNAL_SERVER_ERROR, $e); } return $rpcRequest->produceResponse(true);