Skip to content
Permalink
Browse files

Add a new exception class for routing errors.

When routes cannot be found for reverse routing or parsing a URL
a special error is raised. This error will be used to trigger special
error pages that make it easier to understand which routes are
connected.
  • Loading branch information...
markstory committed Jul 1, 2014
1 parent 1e23ef9 commit ac16ff1bbc179865e24f8102b99f50d9461b5fbf
Showing with 7 additions and 12 deletions.
  1. +4 −9 src/Routing/Router.php
  2. +3 −3 tests/TestCase/Routing/RouterTest.php
@@ -16,8 +16,8 @@
use Cake\Core\App;
use Cake\Core\Configure;
use Cake\Error;
use Cake\Network\Request;
use Cake\Routing\Error\MissingRouteException;
use Cake\Routing\ScopedRouteCollection;
use Cake\Routing\Route\Route;
use Cake\Utility\Inflector;
@@ -481,7 +481,7 @@ public static function prefixes() {
*
* @param string $url URL to be parsed
* @return array Parsed elements from URL
* @throws \Cake\Error\Exception When a route cannot be handled
* @throws \Cake\Routing\Error\MissingRouteException When a route cannot be handled
*/
public static function parse($url) {
if (!static::$initialized) {
@@ -496,8 +496,7 @@ public static function parse($url) {
return $collection->parse($url);
}
}
// TODO improve this with a custom exception.
throw new Error\Exception('No routes match the given URL.');
throw new MissingRouteException($url);
}
/**
@@ -849,11 +848,7 @@ protected static function _match($url) {
}
}
// TODO improve with custom exception
throw new Error\Exception(sprintf(
'Unable to find a matching route for %s',
var_export($url, true)
));
throw new MissingRouteException(var_export($url, true));
}
/**
@@ -1074,7 +1074,7 @@ public function testUrlGenerationNamedRoute() {
/**
* Test that using invalid names causes exceptions.
*
* @expectedException \Cake\Error\Exception
* @expectedException \Cake\Routing\Error\MissingRouteException
* @return void
*/
public function testNamedRouteException() {
@@ -2083,7 +2083,7 @@ public function testParsingWithPatternOnAction() {
/**
* Test url() works with patterns on :action
*
* @expectedException Cake\Error\Exception
* @expectedException Cake\Routing\Error\MissingRouteException
* @return void
*/
public function testUrlPatterOnAction() {
@@ -2275,7 +2275,7 @@ public function testRegexRouteMatching() {
/**
* testRegexRouteMatching method
*
* @expectedException Cake\Error\Exception
* @expectedException Cake\Routing\Error\MissingRouteException
* @return void
*/
public function testRegexRouteMatchUrl() {

0 comments on commit ac16ff1

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