[EXCEPTION] Make findOne return NotFoundException

This commit is contained in:
Hugo Sales 2020-09-10 22:25:47 +00:00 committed by Hugo Sales
parent c07a0cdcd5
commit 63d2d58e9e
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
2 changed files with 34 additions and 2 deletions

View File

@ -1,6 +1,7 @@
<?php <?php
// {{{ License // {{{ License
// This file is part of GNU social - https://www.gnu.org/software/social // This file is part of GNU social - https://www.gnu.org/software/social
// //
// GNU social is free software: you can redistribute it and/or modify // GNU social is free software: you can redistribute it and/or modify
@ -15,6 +16,7 @@
// //
// You should have received a copy of the GNU Affero General Public License // You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
// }}} // }}}
/** /**
@ -30,13 +32,13 @@
namespace App\Core\DB; namespace App\Core\DB;
use App\Util\Exception\NotFoundException;
use App\Util\Formatting; use App\Util\Formatting;
use Doctrine\Common\Collections\Criteria; use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Collections\ExpressionBuilder; use Doctrine\Common\Collections\ExpressionBuilder;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use Doctrine\ORM\Query\ResultSetMappingBuilder; use Doctrine\ORM\Query\ResultSetMappingBuilder;
use Exception;
abstract class DB abstract class DB
{ {
@ -117,7 +119,7 @@ abstract class DB
if (count($res) == 1) { if (count($res) == 1) {
return $res[0]; return $res[0];
} else { } 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");
} }
} }

View File

@ -0,0 +1,30 @@
<?php
// {{{ License
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
// }}}
namespace App\Util\Exception;
class NotFoundException extends ServerException
{
public function __construct(string $m)
{
parent::__construct($m);
}
}