Skip to content

Commit 560bf36

Browse files
committed
fix: error handler
check if app is enabled Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent e671cf5 commit 560bf36

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

lib/Service/IdentifyMethod/SignatureMethod/TokenService.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88

99
namespace OCA\Libresign\Service\IdentifyMethod\SignatureMethod;
1010

11+
use OCA\Libresign\Exception\LibresignException;
1112
use OCA\Libresign\Service\MailService;
1213
use OCP\AppFramework\OCS\OCSForbiddenException;
1314
use OCP\IL10N;
1415
use OCP\Security\IHasher;
1516
use OCP\Security\ISecureRandom;
1617
use OCP\Server;
18+
use Psr\Container\NotFoundExceptionInterface;
1719

1820
class TokenService {
1921
public const TOKEN_LENGTH = 6;
@@ -39,7 +41,12 @@ public function sendCodeByGateway(string $identifier, string $gatewayName): stri
3941
* @return \OCA\TwoFactorGateway\Provider\Gateway\IGateway
4042
*/
4143
private function getGateway(string $gatewayName) {
42-
$factory = Server::get('\OCA\TwoFactorGateway\Service\Gateway\Factory');
44+
try {
45+
$factory = Server::get(\OCA\TwoFactorGateway\Provider\Gateway\Factory::class);
46+
} catch (NotFoundExceptionInterface) {
47+
throw new LibresignException('App Two-Factor Gateway is not installed.');
48+
49+
}
4350
$gateway = $factory->getGateway($gatewayName);
4451
if (!$gateway->getConfig()->isComplete()) {
4552
throw new OCSForbiddenException($this->l10n->t('Gateway %s not configured on Two-Factor Gateway.', $gatewayName));

0 commit comments

Comments
 (0)