closes #34 (exception code for entity not found)
This commit is contained in:
parent
3574f4849d
commit
af36ccdd93
3 changed files with 8 additions and 5 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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; }
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue