Improved Exception Handling

This commit is contained in:
netkas 2025-02-03 13:02:36 -05:00
parent fdf9da12aa
commit 24530f5494
2 changed files with 5 additions and 3 deletions

View file

@ -6,6 +6,7 @@
use Socialbox\Enums\Flags\SessionFlags;
use Socialbox\Enums\StandardError;
use Socialbox\Exceptions\DatabaseOperationException;
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
use Socialbox\Exceptions\Standard\StandardRpcException;
use Socialbox\Interfaces\SerializableInterface;
use Socialbox\Managers\CaptchaManager;
@ -23,7 +24,7 @@
{
if(!$rpcRequest->containsParameter('answer'))
{
return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, 'The answer parameter is required');
throw new MissingRpcArgumentException('answer');
}
$session = $request->getSession();
@ -32,7 +33,7 @@
{
if(CaptchaManager::getCaptcha($session->getPeerUuid())?->isExpired())
{
return $rpcRequest->produceError(StandardError::CAPTCHA_EXPIRED, 'The captcha has expired');
return $rpcRequest->produceError(StandardError::EXPIRED, 'The captcha has expired');
}
}
catch(DatabaseOperationException $e)

View file

@ -16,7 +16,8 @@
case NOT_FOUND = -105;
case RESOLUTION_FAILED = -106;
case CONFLICT = -107;
case CRYPTOGRAPHIC_ERROR = -108;
case EXPIRED = -108;
case CRYPTOGRAPHIC_ERROR = -109;
// RPC Errors
case RPC_METHOD_NOT_FOUND = -1000;