From edf6677256ac5814dbae2a8aad5b81a89364df5e Mon Sep 17 00:00:00 2001 From: netkas Date: Tue, 14 Jan 2025 14:53:21 -0500 Subject: [PATCH] Add error handling and update parameter in RPC request --- src/Socialbox/SocialClient.php | 2 +- src/Socialbox/Socialbox.php | 40 ++++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/Socialbox/SocialClient.php b/src/Socialbox/SocialClient.php index c3a6a7e..3ff5a11 100644 --- a/src/Socialbox/SocialClient.php +++ b/src/Socialbox/SocialClient.php @@ -494,7 +494,7 @@ { return (bool)$this->sendRequest( new RpcRequest(StandardMethods::SETTINGS_SET_DISPLAY_NAME->value, Utilities::randomCrc32(), [ - 'display_name' => $displayName + 'name' => $displayName ]) )->getResponse()->getResult(); } diff --git a/src/Socialbox/Socialbox.php b/src/Socialbox/Socialbox.php index c00e18f..703e05a 100644 --- a/src/Socialbox/Socialbox.php +++ b/src/Socialbox/Socialbox.php @@ -56,27 +56,35 @@ // Handle the request type, only `init` and `dhe` are not encrypted using the session's encrypted key // RPC Requests must be encrypted and signed by the client, vice versa for server responses. - switch($clientRequest->getRequestType()) + try { - case RequestType::INFO: - self::handleInformationRequest(); - break; + switch($clientRequest->getRequestType()) + { + case RequestType::INFO: + self::handleInformationRequest(); + break; - case RequestType::INITIATE_SESSION: - self::handleInitiateSession($clientRequest); - break; + case RequestType::INITIATE_SESSION: + self::handleInitiateSession($clientRequest); + break; - case RequestType::DHE_EXCHANGE: - self::handleDheExchange($clientRequest); - break; + case RequestType::DHE_EXCHANGE: + self::handleDheExchange($clientRequest); + break; - case RequestType::RPC: - self::handleRpc($clientRequest); - break; + case RequestType::RPC: + self::handleRpc($clientRequest); + break; - default: - self::returnError(400, StandardError::BAD_REQUEST, 'Invalid Request-Type header'); + default: + self::returnError(400, StandardError::BAD_REQUEST, 'Invalid Request-Type header'); + } } + catch(Exception $e) + { + self::returnError(500, StandardError::INTERNAL_SERVER_ERROR, 'An internal error occurred while processing the request', $e); + } + } /** @@ -607,7 +615,7 @@ privateKey: Configuration::getCryptographyConfiguration()->getHostPrivateKey() ); } - catch (Exceptions\CryptographyException $e) + catch (Exception $e) { self::returnError(500, StandardError::INTERNAL_SERVER_ERROR, 'Failed to encrypt the server response', $e); return;