simple-php-router
simple-php-router copied to clipboard
Double render setRewriteCallback
SimpleRouter::error(function(Request $request, \Exception $exception) { $request->setRewriteCallback('ErrorController@notFound'); });
Hello,
can you please describe your issue/ question more detailed? Also please provide more of your code and an error message, if one exists. Thank you!
~ Marius
Hello, i have same issue.
This is how you can recreate it
I'm trying to add custom Exception handler and setRewriteCallback instead of redirect.
ExceptionHandler
class CustomExceptionHandler implements IExceptionHandler
{
public function handleError(Request $request, \Throwable $error): void
{
/* The router will throw the NotFoundHttpException on 404 */
if ($error instanceof NotFoundHttpException) {
// Render custom 404-page
$request->setRewriteCallback('Controller\PageController@notFound');
return;
}
throw $error;
}
}
Controller:
class PageController
{
public function notFound()
{
SimpleRouter::response()->httpCode(404);
echo "check\n";
}
}
And there is no routes only one group with set Custom Exception Handler class
SimpleRouter::group(["exceptionHandler" => \Reaspekt\Exception\CustomExceptionHandler::class], function () {
});
Desired outcome: One "check" string printed on page
Outcome: I have two "check" strings printed
Thanks for the detailed report.
What happens if you return an output in the notFound method?