Skip to content

Commit 898cf95

Browse files
committed
Catch exceptions in predict command
Signed-off-by: Victor Lap <victorlap@outlook.com>
1 parent d8adac3 commit 898cf95

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

lib/Command/Predict.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
namespace OCA\SuspiciousLogin\Command;
2626

27+
use OCA\SuspiciousLogin\Exception\ModelNotFoundException;
28+
use OCA\SuspiciousLogin\Exception\ServiceException;
2729
use OCA\SuspiciousLogin\Service\EstimatorService;
2830
use OCA\SuspiciousLogin\Service\Ipv4Strategy;
2931
use OCA\SuspiciousLogin\Service\IpV6Strategy;
@@ -70,14 +72,24 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7072
$uid = $input->getArgument('uid');
7173
$ip = $input->getArgument('ip');
7274
$modelId = $input->getArgument('model');
73-
if (!$this->estimatorService->predict(
74-
$uid,
75-
$ip,
76-
$input->getOption('v6') ? new IpV6Strategy() : new Ipv4Strategy(),
77-
$modelId ? (int)$modelId : null)) {
78-
$output->writeln("WARN: IP $ip is suspicious");
79-
return 1;
75+
76+
try {
77+
if (!$this->estimatorService->predict(
78+
$uid,
79+
$ip,
80+
$input->getOption('v6') ? new IpV6Strategy() : new Ipv4Strategy(),
81+
$modelId ? (int)$modelId : null)) {
82+
$output->writeln("WARN: IP $ip is suspicious");
83+
return 1;
84+
}
85+
} catch (ModelNotFoundException $ex) {
86+
$output->writeln('<error>Could not predict suspiciousness: ' . $ex->getMessage() . '</error>');
87+
return 2;
88+
} catch (ServiceException $ex) {
89+
$output->writeln('<error>Could not predict suspiciousness: ' . $ex->getMessage() . '</error>');
90+
return 3;
8091
}
92+
8193
$output->writeln("OK: IP $ip is not suspicious");
8294
return 0;
8395
}

0 commit comments

Comments
 (0)