|
24 | 24 |
|
25 | 25 | namespace OCA\SuspiciousLogin\Command; |
26 | 26 |
|
| 27 | +use OCA\SuspiciousLogin\Exception\ModelNotFoundException; |
| 28 | +use OCA\SuspiciousLogin\Exception\ServiceException; |
27 | 29 | use OCA\SuspiciousLogin\Service\EstimatorService; |
28 | 30 | use OCA\SuspiciousLogin\Service\Ipv4Strategy; |
29 | 31 | use OCA\SuspiciousLogin\Service\IpV6Strategy; |
@@ -70,14 +72,24 @@ protected function execute(InputInterface $input, OutputInterface $output): int |
70 | 72 | $uid = $input->getArgument('uid'); |
71 | 73 | $ip = $input->getArgument('ip'); |
72 | 74 | $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; |
80 | 91 | } |
| 92 | + |
81 | 93 | $output->writeln("OK: IP $ip is not suspicious"); |
82 | 94 | return 0; |
83 | 95 | } |
|
0 commit comments