diff --git a/backend/lib/Controller/EntityController.php b/backend/lib/Controller/EntityController.php index 46aadc8..e03fde4 100644 --- a/backend/lib/Controller/EntityController.php +++ b/backend/lib/Controller/EntityController.php @@ -55,7 +55,7 @@ class EntityController extends Controller { try { return $q->getSingleResult(); } catch (\Doctrine\ORM\NoResultException $e) { - throw new \Exception('No entity found with UUID: ' . $uuid); + throw new \Exception('No entity found with UUID: ' . $uuid, 404); } } diff --git a/backend/lib/View/HTTP/Response.php b/backend/lib/View/HTTP/Response.php index a5e538b..454b6cd 100644 --- a/backend/lib/View/HTTP/Response.php +++ b/backend/lib/View/HTTP/Response.php @@ -123,9 +123,7 @@ class Response { public function getHeader($header) { return $this->headers[$header]; } public function getCode() { return $this->code; } public function setCode($code) { $this->code = $code; } - static public function getCodeDescription($code) { - return (isset(self::$codes[$code])) ? self::$codes[$code] : FALSE; - } + static public function getCodeDescription($code) { return (isset(self::$codes[$code])) ? self::$codes[$code] : FALSE; } } ?> diff --git a/backend/lib/View/View.php b/backend/lib/View/View.php index be14230..114c29f 100644 --- a/backend/lib/View/View.php +++ b/backend/lib/View/View.php @@ -82,10 +82,15 @@ abstract class View { $this->exceptionHandler(new \ErrorException($errstr, 0, $errno, $errfile, $errline)); } + /** + * Handles exceptions and sets HTTP return code + * + * @param \Exception $exception + */ final public function exceptionHandler(\Exception $exception) { $this->addException($exception, Util\Debug::isActivated()); - $code = ($exception->getCode() == 0 && HTTP\Response::getCodeDescription($exception->getCode())) ? 400 : $exception->getCode(); + $code = ($exception->getCode() == 0 || !HTTP\Response::getCodeDescription($exception->getCode())) ? 400 : $exception->getCode(); $this->response->setCode($code); $this->send();