Navigation Menu

Skip to content

Commit

Permalink
Moved Http exceptions to the Network namespaces
Browse files Browse the repository at this point in the history
Also sarted to remove the hard dependency on Core\Exception\Exception
where it offers no added value
  • Loading branch information
lorenzo committed Aug 30, 2014
1 parent 3265326 commit d6dcee4
Show file tree
Hide file tree
Showing 25 changed files with 86 additions and 72 deletions.
6 changes: 3 additions & 3 deletions src/Auth/BasicAuthenticate.php
Expand Up @@ -14,7 +14,7 @@
*/
namespace Cake\Auth;

use Cake\Error;
use Cake\Network\Exception\UnauthorizedException;
use Cake\Network\Request;
use Cake\Network\Response;

Expand Down Expand Up @@ -85,10 +85,10 @@ public function getUser(Request $request) {
* @param Request $request A request object.
* @param Response $response A response object.
* @return void
* @throws \Cake\Error\UnauthorizedException
* @throws \Cake\Network\Exception\UnauthorizedException
*/
public function unauthenticated(Request $request, Response $response) {
$Exception = new Error\UnauthorizedException();
$Exception = new UnauthorizedException();
$Exception->responseHeader(array($this->loginHeaders($request)));
throw $Exception;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Controller/Component/AuthComponent.php
Expand Up @@ -19,9 +19,9 @@
use Cake\Controller\Controller;
use Cake\Core\App;
use Cake\Core\Exception\Exception;
use Cake\Error;
use Cake\Error\Debugger;
use Cake\Event\Event;
use Cake\Network\Exception\ForbiddenException;
use Cake\Network\Request;
use Cake\Network\Response;
use Cake\Routing\Router;
Expand Down Expand Up @@ -391,11 +391,11 @@ protected function _isLoginAction(Controller $controller) {
*
* @param \Cake\Controller\Controller $controller A reference to the controller object
* @return \Cake\Network\Response
* @throws \Cake\Error\ForbiddenException
* @throws \Cake\Network\Exception\ForbiddenException
*/
protected function _unauthorized(Controller $controller) {
if ($this->_config['unauthorizedRedirect'] === false) {
throw new Error\ForbiddenException($this->_config['authError']);
throw new ForbiddenException($this->_config['authError']);
}

$this->flash($this->_config['authError']);
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Component/CsrfComponent.php
Expand Up @@ -15,8 +15,8 @@
namespace Cake\Controller\Component;

use Cake\Controller\Component;
use Cake\Error\ForbiddenException;
use Cake\Event\Event;
use Cake\Network\Exception\ForbiddenException;
use Cake\Network\Request;
use Cake\Network\Response;
use Cake\Utility\Security;
Expand Down Expand Up @@ -131,7 +131,7 @@ protected function _setCookie(Request $request, Response $response) {
* Validate the request data against the cookie token.
*
* @param \Cake\Network\Request $request The request to validate against.
* @throws \Cake\Error\ForbiddenException when the CSRF token is invalid or missing.
* @throws \Cake\Network\Exception\ForbiddenException when the CSRF token is invalid or missing.
* @return void
*/
protected function _validateToken(Request $request) {
Expand Down
6 changes: 3 additions & 3 deletions src/Controller/Component/PaginatorComponent.php
Expand Up @@ -15,7 +15,7 @@
namespace Cake\Controller\Component;

use Cake\Controller\Component;
use Cake\Error;
use Cake\Network\Exception\NotFoundException;
use Cake\ORM\Query;
use Cake\ORM\Table;

Expand Down Expand Up @@ -140,7 +140,7 @@ public function implementedEvents() {
* @param \Cake\Datasource\RepositoryInterface|\Cake\ORM\Query $object The table or query to paginate.
* @param array $settings The settings/configuration used for pagination.
* @return array Query results
* @throws \Cake\Error\NotFoundException
* @throws \Cake\Network\Exception\NotFoundException
*/
public function paginate($object, array $settings = []) {
if ($object instanceof Query) {
Expand Down Expand Up @@ -214,7 +214,7 @@ public function paginate($object, array $settings = []) {
);

if ($requestedPage > $page) {
throw new Error\NotFoundException();
throw new NotFoundException();
}

return $results;
Expand Down
10 changes: 5 additions & 5 deletions src/Controller/Component/SecurityComponent.php
Expand Up @@ -17,8 +17,8 @@
use Cake\Controller\Component;
use Cake\Controller\Controller;
use Cake\Core\Configure;
use Cake\Error;
use Cake\Event\Event;
use Cake\Network\Exception\BadRequestException;
use Cake\Network\Request;
use Cake\Utility\Hash;
use Cake\Utility\Security;
Expand Down Expand Up @@ -175,11 +175,11 @@ public function requireAuth($actions) {
* @return mixed If specified, controller blackHoleCallback's response, or no return otherwise
* @see SecurityComponent::$blackHoleCallback
* @link http://book.cakephp.org/2.0/en/core-libraries/components/security-component.html#handling-blackhole-callbacks
* @throws \Cake\Error\BadRequestException
* @throws \Cake\Network\Exception\BadRequestException
*/
public function blackHole(Controller $controller, $error = '') {
if (!$this->_config['blackHoleCallback']) {
throw new Error\BadRequestException('The request has been black-holed');
throw new BadRequestException('The request has been black-holed');
}
return $this->_callback($controller, $this->_config['blackHoleCallback'], array($error));
}
Expand Down Expand Up @@ -388,11 +388,11 @@ public function generateToken(Request $request) {
* @param string $method Method to execute
* @param array $params Parameters to send to method
* @return mixed Controller callback method's response
* @throws \Cake\Error\BadRequestException When a the blackholeCallback is not callable.
* @throws \Cake\Network\Exception\BadRequestException When a the blackholeCallback is not callable.
*/
protected function _callback(Controller $controller, $method, $params = array()) {
if (!is_callable(array($controller, $method))) {
throw new Error\BadRequestException('The request has been black-holed');
throw new BadRequestException('The request has been black-holed');
}
return call_user_func_array(array(&$controller, $method), empty($params) ? null : $params);
}
Expand Down
5 changes: 3 additions & 2 deletions src/Controller/Controller.php
Expand Up @@ -28,6 +28,7 @@
use Cake\Utility\Inflector;
use Cake\Utility\MergeVariablesTrait;
use Cake\View\ViewVarsTrait;
use LogicException;

/**
* Application controller class for organization of business logic.
Expand Down Expand Up @@ -350,15 +351,15 @@ public function setRequest(Request $request) {
* exists and isn't private.
*
* @return mixed The resulting response.
* @throws \Cake\Core\Exception\Exception When request is not set.
* @throws \LogicException When request is not set.
* @throws \Cake\Controller\Error\PrivateActionException When actions are not public or prefixed by _
* @throws \Cake\Controller\Error\MissingActionException When actions are not defined.
*/
public function invokeAction() {
try {
$request = $this->request;
if (!isset($request)) {
throw new Exception('No Request object configured. Cannot invoke action');
throw new LogicException('No Request object configured. Cannot invoke action');
}
$method = new \ReflectionMethod($this, $request->params['action']);
if ($this->_isPrivateAction($method, $request)) {
Expand Down
1 change: 1 addition & 0 deletions src/Error/BaseErrorHandler.php
Expand Up @@ -18,6 +18,7 @@
use Cake\Error\Debugger;
use Cake\Log\Log;
use Cake\Routing\Router;
use Cake\Network\Exception\InternalErrorException;

/**
* Base error handler that provides logic common to the CLI + web
Expand Down
10 changes: 6 additions & 4 deletions src/Error/Debugger.php
Expand Up @@ -15,10 +15,11 @@
namespace Cake\Error;

use Cake\Core\Configure;
use Cake\Core\Exception\Exception;
use Cake\Log\Log;
use Cake\Utility\Hash;
use Cake\Utility\String;
use Exception;
use InvalidArgumentException;

/**
* Provide custom logging and error handling.
Expand Down Expand Up @@ -583,7 +584,7 @@ protected static function _object($var, $depth, $indent) {
return $out . "\n" .
substr(static::_array($var->__debugInfo(), $depth - 1, $indent), 1, -1) .
$end . '}';
} catch (\Exception $e) {
} catch (Exception $e) {
return $out . "\n(unable to export object)\n }";
}
}
Expand Down Expand Up @@ -625,15 +626,16 @@ protected static function _object($var, $depth, $indent) {
* @param string $format The format you want errors to be output as.
* Leave null to get the current format.
* @return mixed Returns null when setting. Returns the current format when getting.
* @throws \Cake\Core\Exception\Exception when choosing a format that doesn't exist.
* @throws \InvalidArgumentException when choosing a format that doesn't exist.
*/
public static function outputAs($format = null) {
$self = Debugger::getInstance();
if ($format === null) {
return $self->_outputFormat;
}

if ($format !== false && !isset($self->_templates[$format])) {
throw new Exception('Invalid Debugger output format.');
throw new InvalidArgumentException('Invalid Debugger output format.');
}
$self->_outputFormat = $format;
}
Expand Down
5 changes: 3 additions & 2 deletions src/Error/ErrorHandler.php
Expand Up @@ -18,6 +18,7 @@

use Cake\Core\App;
use Cake\Error\Debugger;
use Exception;

/**
* Error Handler provides basic error and exception handling for your application. It captures and
Expand Down Expand Up @@ -132,13 +133,13 @@ protected function _displayException($exception) {
$renderer = App::className($this->_options['exceptionRenderer'], 'Error');
try {
if (!$renderer) {
throw new \Exception("$renderer is an invalid class.");
throw new Exception("$renderer is an invalid class.");
}
$error = new $renderer($exception);
$response = $error->render();
$this->_clearOutput();
$this->_sendResponse($response);
} catch (\Exception $e) {
} catch (Exception $e) {
// Disable trace for internal errors.
$this->_options['trace'] = false;
$message = sprintf("[%s] %s\n%s", // Keeping same message format
Expand Down
11 changes: 7 additions & 4 deletions src/Error/ExceptionRenderer.php
Expand Up @@ -17,14 +17,17 @@
use Cake\Controller\Controller;
use Cake\Controller\ErrorController;
use Cake\Core\Configure;
use Cake\Core\Exception\Exception as CakeException;
use Cake\Core\Exception\MissingPluginException;
use Cake\Error;
use Cake\Event\Event;
use Cake\Network\Exception\HttpException;
use Cake\Network\Request;
use Cake\Network\Response;
use Cake\Routing\Router;
use Cake\Utility\Inflector;
use Cake\View\Error\MissingViewException;
use Exception;

/**
* Exception Renderer.
Expand Down Expand Up @@ -80,7 +83,7 @@ class ExceptionRenderer {
*
* @param \Exception $exception Exception
*/
public function __construct(\Exception $exception) {
public function __construct(Exception $exception) {
$this->error = $exception;
$this->controller = $this->_getController();
}
Expand All @@ -102,7 +105,7 @@ protected function _getController() {
try {
$controller = new ErrorController($request, $response);
$controller->startupProcess();
} catch (\Exception $e) {
} catch (Exception $e) {
if (!empty($controller) && isset($controller->RequestHandler)) {
$event = new Event('Controller.startup', $controller);
$controller->RequestHandler->startup($event);
Expand All @@ -127,7 +130,7 @@ public function render() {
$template = $this->_template($exception, $method, $code);

$isDebug = Configure::read('debug');
if (($isDebug || $exception instanceof Error\HttpException) &&
if (($isDebug || $exception instanceof HttpException) &&
method_exists($this, $method)
) {
return $this->_customMethod($method, $exception);
Expand All @@ -148,7 +151,7 @@ public function render() {
'_serialize' => array('message', 'url', 'code')
));

if ($exception instanceof Error\Exception && $isDebug) {
if ($exception instanceof CakeException && $isDebug) {
$this->controller->set($this->error->getAttributes());
}
return $this->_outputMessage($template);
Expand Down
Expand Up @@ -11,7 +11,7 @@
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Error;
namespace Cake\Network\Exception;

/**
* Represents an HTTP 400 error.
Expand Down
Expand Up @@ -11,7 +11,7 @@
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Error;
namespace Cake\Network\Exception;

/**
* Represents an HTTP 403 error.
Expand Down
Expand Up @@ -11,7 +11,7 @@
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Error;
namespace Cake\Network\Exception;

use Cake\Core\Exception\Exception;

Expand Down
Expand Up @@ -11,7 +11,8 @@
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Error;

namespace Cake\Network\Exception;

/**
* Represents an HTTP 500 error.
Expand Down
Expand Up @@ -11,7 +11,7 @@
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Error;
namespace Cake\Network\Exception;

/**
* Represents an HTTP 405 error.
Expand Down
Expand Up @@ -11,7 +11,7 @@
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Error;
namespace Cake\Network\Exception;

/**
* Represents an HTTP 404 error.
Expand Down
Expand Up @@ -11,7 +11,7 @@
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Error;
namespace Cake\Network\Exception;

/**
* Not Implemented Exception - used when an API method is not implemented
Expand Down
Expand Up @@ -11,14 +11,14 @@
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Network\Error;
namespace Cake\Network\Exception;

use Cake\Core\Exception\Exception;
use RuntimeException;

/**
* Exception class for Socket. This exception will be thrown from Socket, Email, HttpSocket
* SmtpTransport, MailTransport and HttpResponse when it encounters an error.
*
*/
class SocketException extends Exception {
class SocketException extends RuntimeException {
}
Expand Up @@ -11,7 +11,7 @@
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Error;
namespace Cake\Network\Exception;

/**
* Represents an HTTP 401 error.
Expand Down

0 comments on commit d6dcee4

Please sign in to comment.