containsParameter('answer')) { throw new MissingRpcArgumentException('answer'); } try { $session = $request->getSession(); if(CaptchaManager::getCaptcha($session->getPeerUuid())?->isExpired()) { return $rpcRequest->produceError(StandardError::EXPIRED, 'The captcha has expired'); } } catch(DatabaseOperationException $e) { throw new StandardRpcException("There was an unexpected error while trying to get the captcha", StandardError::INTERNAL_SERVER_ERROR, $e); } try { $result = CaptchaManager::answerCaptcha($session->getPeerUuid(), $rpcRequest->getParameter('answer')); if($result) { SessionManager::updateFlow($session, [SessionFlags::VER_IMAGE_CAPTCHA]); } } catch (DatabaseOperationException $e) { throw new StandardRpcException("There was an unexpected error while trying to answer the captcha", StandardError::INTERNAL_SERVER_ERROR, $e); } return $rpcRequest->produceResponse($result); } }