started improving exception handling
This commit is contained in:
parent
1756d541ca
commit
2b64e8969a
2 changed files with 18 additions and 3 deletions
14
lib/Exceptions/NotFoundException.php
Normal file
14
lib/Exceptions/NotFoundException.php
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace OCA\GroupfolderFilesystemSnapshots\Exceptions;
|
||||||
|
|
||||||
|
class NotFoundException extends \RuntimeException {
|
||||||
|
public function __construct($entity, array|string $criteria) {
|
||||||
|
$message = sprintf(
|
||||||
|
"Could not find %s with criteria %s",
|
||||||
|
class_exists($entity) ? array_pop(explode('\\', $entity)) : $entity,
|
||||||
|
is_string($criteria) ? $criteria : json_encode($criteria),
|
||||||
|
);
|
||||||
|
parent::__construct($message);
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,6 +6,7 @@ use Exception;
|
||||||
use OCP\AppFramework\Db\DoesNotExistException;
|
use OCP\AppFramework\Db\DoesNotExistException;
|
||||||
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
|
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
|
||||||
|
|
||||||
|
use OCA\GroupfolderFilesystemSnapshots\Exceptions\NotFoundException;
|
||||||
use OCA\GroupfolderFilesystemSnapshots\Db\DiffTask;
|
use OCA\GroupfolderFilesystemSnapshots\Db\DiffTask;
|
||||||
use OCA\GroupfolderFilesystemSnapshots\Db\DiffTaskMapper;
|
use OCA\GroupfolderFilesystemSnapshots\Db\DiffTaskMapper;
|
||||||
use OCA\GroupfolderFilesystemSnapshots\Db\DiffTaskResult;
|
use OCA\GroupfolderFilesystemSnapshots\Db\DiffTaskResult;
|
||||||
|
@ -36,10 +37,10 @@ class DiffTaskService {
|
||||||
/**
|
/**
|
||||||
* @return never
|
* @return never
|
||||||
*/
|
*/
|
||||||
private function handleException ($e) {
|
private function handleException ($e, $criteria) {
|
||||||
if ($e instanceof DoesNotExistException ||
|
if ($e instanceof DoesNotExistException ||
|
||||||
$e instanceof MultipleObjectsReturnedException) {
|
$e instanceof MultipleObjectsReturnedException) {
|
||||||
throw new NotFoundException($e->getMessage());
|
throw new NotFoundException($e->getMessage(), $criteria);
|
||||||
} else {
|
} else {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
@ -49,7 +50,7 @@ class DiffTaskService {
|
||||||
try {
|
try {
|
||||||
return $this->mapper->find($id, $userId);
|
return $this->mapper->find($id, $userId);
|
||||||
} catch(Exception $e) {
|
} catch(Exception $e) {
|
||||||
$this->handleException($e);
|
$this->handleException($e, ["userId" => $userId, "id" => $id]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue