diff --git a/composer.json b/composer.json index fed70ff..fd426f1 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,7 @@ "php": ">=5.3.0" }, "autoload": { - "psr-0": { "pjdietz\\WellRESTed": "src/" } + "psr-0": { "pjdietz\\WellRESTed": "src/" }, + "classmap": ["src/pjdietz/WellRESTed/Exceptions/HttpExceptions.php"] } } diff --git a/src/pjdietz/WellRESTed/Exceptions/HttpExceptions.php b/src/pjdietz/WellRESTed/Exceptions/HttpExceptions.php new file mode 100644 index 0000000..c18bc5c --- /dev/null +++ b/src/pjdietz/WellRESTed/Exceptions/HttpExceptions.php @@ -0,0 +1,39 @@ +request = $request; $this->args = $args; $this->response = new Response(); - $this->buildResponse(); + try { + $this->buildResponse(); + } catch (HttpException $e) { + $this->response->setStatusCode($e->getCode()); + $this->response->setBody($e->getMessage()); + } return $this->response; } @@ -51,6 +57,10 @@ abstract class Handler implements HandlerInterface * Prepare the Response. Override this method if your subclass needs to * repond to any non-standard HTTP methods. Otherwise, override the * get, post, put, etc. methods. + * + * An uncaught HttpException (or subclass) will be converted to a response + * using the exception's code as the status code and the exceptios message + * as the body. */ protected function buildResponse() {