Permalink
Browse files

Redid the HttpException class to prevent code duplication: the logic …

…for shutting Fuel down doesn't have to be in each exception. Only generating the Response is unique.
  • Loading branch information...
1 parent fc84c00 commit 839c36ddfe9bf6830e39d6d2d30901b87448ecff @jschreuder jschreuder committed Jan 18, 2012
Showing with 21 additions and 17 deletions.
  1. +17 −1 classes/httpexception.php
  2. +4 −16 classes/httpexceptions.php
@@ -15,5 +15,21 @@
abstract class HttpException extends \FuelException
{
- abstract public function handle();
+ /**
+ * Must return a response object for the handle method
+ *
+ * @return Response
+ */
+ abstract protected function response();
+
+ /**
+ * When this type of exception isn't caught this method is called by
+ * Error::exception_handler() to deal with the problem.
+ */
+ public function handle()
+ {
+ $response = $this->response();
+ \Event::shutdown();
+ $response->send(true);
+ }
}
@@ -18,28 +18,16 @@
*/
class HttpNotFoundException extends \Request404Exception
{
- /**
- * When this type of exception isn't caught this method is called by
- * Error::exception_handler() to deal with the problem.
- */
- public function handle()
+ public function response()
{
- $response = new \Response(\View::forge('404'), 404);
- \Event::shutdown();
- $response->send(true);
+ return new \Response(\View::forge('404'), 404);
}
}
class HttpServerErrorException extends \HttpException
{
- /**
- * When this type of exception isn't caught this method is called by
- * Error::exception_handler() to deal with the problem.
- */
- public function handle()
+ public function response()
{
- $response = new \Response(\View::forge('500'), 500);
- \Event::shutdown();
- $response->send(true);
+ return new \Response(\View::forge('500'), 500);
}
}

0 comments on commit 839c36d

Please sign in to comment.