From 63d2d58e9e9a7583e7a0cacf8e74c45cb25faaee Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Thu, 10 Sep 2020 22:25:47 +0000 Subject: [PATCH] [EXCEPTION] Make findOne return NotFoundException --- src/Core/DB/DB.php | 6 +++-- src/Util/Exception/NotFoundException.php | 30 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 src/Util/Exception/NotFoundException.php diff --git a/src/Core/DB/DB.php b/src/Core/DB/DB.php index ec9236ea5d..a4c5fea12d 100644 --- a/src/Core/DB/DB.php +++ b/src/Core/DB/DB.php @@ -1,6 +1,7 @@ . + // }}} /** @@ -30,13 +32,13 @@ namespace App\Core\DB; +use App\Util\Exception\NotFoundException; use App\Util\Formatting; use Doctrine\Common\Collections\Criteria; use Doctrine\Common\Collections\ExpressionBuilder; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Query; use Doctrine\ORM\Query\ResultSetMappingBuilder; -use Exception; abstract class DB { @@ -117,7 +119,7 @@ abstract class DB if (count($res) == 1) { return $res[0]; } else { - throw new Exception("No value in table {$table} matches the requested criteria"); + throw new NotFoundException("No value in table {$table} matches the requested criteria"); } } diff --git a/src/Util/Exception/NotFoundException.php b/src/Util/Exception/NotFoundException.php new file mode 100644 index 0000000000..8e4a714bc3 --- /dev/null +++ b/src/Util/Exception/NotFoundException.php @@ -0,0 +1,30 @@ +. + +// }}} + +namespace App\Util\Exception; + +class NotFoundException extends ServerException +{ + public function __construct(string $m) + { + parent::__construct($m); + } +}