Add exception handling for method execution
This commit is contained in:
parent
ea2fa30e6d
commit
8c323c3053
1 changed files with 15 additions and 1 deletions
|
@ -3,10 +3,12 @@
|
||||||
namespace Socialbox;
|
namespace Socialbox;
|
||||||
|
|
||||||
use ConfigLib\Configuration;
|
use ConfigLib\Configuration;
|
||||||
|
use Exception;
|
||||||
use Socialbox\Classes\RpcHandler;
|
use Socialbox\Classes\RpcHandler;
|
||||||
use Socialbox\Enums\StandardError;
|
use Socialbox\Enums\StandardError;
|
||||||
use Socialbox\Enums\StandardMethods;
|
use Socialbox\Enums\StandardMethods;
|
||||||
use Socialbox\Exceptions\RpcException;
|
use Socialbox\Exceptions\RpcException;
|
||||||
|
use Socialbox\Exceptions\StandardException;
|
||||||
|
|
||||||
class Socialbox
|
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)
|
if($response !== null)
|
||||||
{
|
{
|
||||||
$results[] = $response;
|
$results[] = $response;
|
||||||
|
|
Loading…
Add table
Reference in a new issue