Forgot to catch exceptions in static routes
This commit is contained in:
parent
451a1c0576
commit
b6ec262d0e
|
|
@ -35,6 +35,19 @@ class Router implements HandlerInterface
|
||||||
$this->errorHandlers = array();
|
$this->errorHandlers = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function tryResponse($handler, $request, $args)
|
||||||
|
{
|
||||||
|
$response = null;
|
||||||
|
try {
|
||||||
|
$response = $handler->getResponse($request, $args);
|
||||||
|
} catch (HttpException $e) {
|
||||||
|
$response = new Response();
|
||||||
|
$response->setStatusCode($e->getCode());
|
||||||
|
$response->setBody($e->getMessage());
|
||||||
|
}
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the response built by the handler based on the request
|
* Return the response built by the handler based on the request
|
||||||
*
|
*
|
||||||
|
|
@ -47,19 +60,13 @@ class Router implements HandlerInterface
|
||||||
$path = $request->getPath();
|
$path = $request->getPath();
|
||||||
if (array_key_exists($path, $this->routes)) {
|
if (array_key_exists($path, $this->routes)) {
|
||||||
$handler = new $this->routes[$path]();
|
$handler = new $this->routes[$path]();
|
||||||
$response = $handler->getResponse($request, $args);
|
$response = tryResponse($handler, $request, $args);
|
||||||
} else {
|
} else {
|
||||||
foreach ($this->routes as $path => $route) {
|
foreach ($this->routes as $path => $route) {
|
||||||
// Only take elements that are not $path => $handler mapped.
|
// Only take elements that are not $path => $handler mapped.
|
||||||
if (is_int($path)) {
|
if (is_int($path)) {
|
||||||
/** @var HandlerInterface $route */
|
/** @var HandlerInterface $route */
|
||||||
try {
|
$response = $this->tryResponse($route, $request, $args);
|
||||||
$response = $route->getResponse($request, $args);
|
|
||||||
} catch (HttpException $e) {
|
|
||||||
$response = new Response();
|
|
||||||
$response->setStatusCode($e->getCode());
|
|
||||||
$response->setBody($e->getMessage());
|
|
||||||
}
|
|
||||||
if ($response) break;
|
if ($response) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue