Skip to content
Permalink
Browse files

Moved Http exceptions to the Network namespaces

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 d6dcee431a291b1dffcdf03677000cb34c3e575e
@@ -14,7 +14,7 @@
*/
namespace Cake\Auth;
use Cake\Error;
use Cake\Network\Exception\UnauthorizedException;
use Cake\Network\Request;
use Cake\Network\Response;
@@ -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;
}
@@ -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;
@@ -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']);
@@ -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;
@@ -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) {
@@ -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;
@@ -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) {
@@ -214,7 +214,7 @@ public function paginate($object, array $settings = []) {
);
if ($requestedPage > $page) {
throw new Error\NotFoundException();
throw new NotFoundException();
}
return $results;
@@ -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;
@@ -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));
}
@@ -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);
}
@@ -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.
@@ -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)) {
@@ -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
@@ -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.
@@ -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 }";
}
}
@@ -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;
}
@@ -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
@@ -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
@@ -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.
@@ -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();
}
@@ -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);
@@ -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);
@@ -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);
@@ -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.
@@ -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.
@@ -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;
@@ -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.
@@ -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.
@@ -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.
@@ -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
@@ -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 {
}
@@ -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.
Oops, something went wrong.

0 comments on commit d6dcee4

Please sign in to comment.
You can’t perform that action at this time.