From 8c323c30536150e6718275528e958ac04b6d1c26 Mon Sep 17 00:00:00 2001 From: netkas Date: Tue, 24 Sep 2024 15:01:46 -0400 Subject: [PATCH] Add exception handling for method execution --- src/Socialbox/Socialbox.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Socialbox/Socialbox.php b/src/Socialbox/Socialbox.php index 641036d..3e063af 100644 --- a/src/Socialbox/Socialbox.php +++ b/src/Socialbox/Socialbox.php @@ -3,10 +3,12 @@ namespace Socialbox; use ConfigLib\Configuration; + use Exception; use Socialbox\Classes\RpcHandler; use Socialbox\Enums\StandardError; use Socialbox\Enums\StandardMethods; use Socialbox\Exceptions\RpcException; + use Socialbox\Exceptions\StandardException; class Socialbox { @@ -42,7 +44,19 @@ } } - $response = $method->execute($clientRequest, $rpcRequest); + try + { + $response = $method->execute($clientRequest, $rpcRequest); + } + catch(StandardException $e) + { + $response = $e->produceError($rpcRequest); + } + catch(Exception $e) + { + $response = $rpcRequest->produceError(StandardError::INTERNAL_SERVER_ERROR, 'An error occurred while processing the request'); + } + if($response !== null) { $results[] = $response;