Refactor VerificationOtpAuthentication to handle database operation exceptions when retrieving session

https://github.com/nosial/Socialbox-PHP/issues/78
This commit is contained in:
netkas 2025-03-12 13:34:49 -04:00
parent a433ad2593
commit 76a343a36d
Signed by: netkas
GPG key ID: 4D8629441B76E4CC

View file

@ -8,6 +8,7 @@
use Socialbox\Enums\Flags\SessionFlags;
use Socialbox\Enums\StandardError;
use Socialbox\Exceptions\CryptographyException;
use Socialbox\Exceptions\DatabaseOperationException;
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
use Socialbox\Exceptions\Standard\StandardRpcException;
@ -35,7 +36,15 @@
throw new InvalidRpcArgumentException('code', 'Invalid OTP code length');
}
$session = $request->getSession();
try
{
$session = $request->getSession();
}
catch (DatabaseOperationException $e)
{
throw new StandardRpcException('An error occurred while trying to get the session', StandardError::INTERNAL_SERVER_ERROR, $e);
}
if(!$session->flagExists(SessionFlags::VER_OTP))
{
return $rpcRequest->produceError(StandardError::METHOD_NOT_ALLOWED, 'One Time Password verification is not required at this time');