Closed mcdavidsh closed 2 years ago
Hello, i am wondering how pass the 404/500 error view after a catch response. ` $this->router->get('/', [HomeController::class,'show']); $this->router->get('/404', function (View $view){ return $view->make('error.404',); });$this->router->get('/500', function (View $view){ return $view->make('error.500'); }); try { $this->router->dispatch(); } catch (RouteNotFoundException $e) { // It's 404!
$this->router->getPublisher()->publish(new HtmlResponse('Not Found', 404)); } catch (Throwable $e) { // Log and report... $this->router->getPublisher()->publish(new HtmlResponse('Internal error.', 500)); }`
Use $this->router->get('/404', function (View $view){ return $view->make('error.404',); })
$this->router->get('/404', function (View $view){ return $view->make('error.404',); })
Instead of $this->router->getPublisher()->publish(new HtmlResponse('Not Found', 404));
Here you can see: https://github.com/miladrahimi/phprouter#error-handling
Hello, i am wondering how pass the 404/500 error view after a catch response. ` $this->router->get('/', [HomeController::class,'show']); $this->router->get('/404', function (View $view){ return $view->make('error.404',); });$this->router->get('/500', function (View $view){ return $view->make('error.500'); }); try { $this->router->dispatch(); } catch (RouteNotFoundException $e) { // It's 404!
Use
$this->router->get('/404', function (View $view){ return $view->make('error.404',); })