mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-07-11 21:22:17 +00:00
Merge pull request #650 from skipperbent/v5-fix-exception
[BUGFIX] Exception handling improvements
This commit is contained in:
@@ -1037,6 +1037,17 @@ class CustomExceptionHandler implements IExceptionHandler
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Other error */
|
||||||
|
if($error instanceof MyCustomException) {
|
||||||
|
|
||||||
|
$request->setRewriteRoute(
|
||||||
|
// Add new route based on current url (minus query-string) and add custom parameters.
|
||||||
|
(new RouteUrl(url(null, null, []), 'PageController@error'))->setParameters(['exception' => $error])
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
throw $error;
|
throw $error;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -346,7 +346,7 @@ class Router
|
|||||||
/* Verify csrf token for request */
|
/* Verify csrf token for request */
|
||||||
$this->csrfVerifier->handle($this->request);
|
$this->csrfVerifier->handle($this->request);
|
||||||
} catch(Exception $e) {
|
} catch(Exception $e) {
|
||||||
$this->handleException($e);
|
return $this->handleException($e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -444,12 +444,12 @@ class Router
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$this->handleException($e);
|
return $this->handleException($e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($methodNotAllowed === true) {
|
if ($methodNotAllowed === true) {
|
||||||
$message = sprintf('Route "%s" or method "%s" not allowed.', $this->request->getUrl()->getPath(), $this->request->getMethod());
|
$message = sprintf('Route "%s" or method "%s" not allowed.', $this->request->getUrl()->getPath(), $this->request->getMethod());
|
||||||
$this->handleException(new NotFoundHttpException($message, 403));
|
return $this->handleException(new NotFoundHttpException($message, 403));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($this->request->getLoadedRoutes()) === 0) {
|
if (count($this->request->getLoadedRoutes()) === 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user