Make 404 a exception instead of a response
Opened this issue · 5 comments
Using exception handling we can make errors catchable by type. If we treat the error as an usual route we can also attach routines to it so it can respect content negotiation (as mentioned on #109).
- Throw
Respect\Rest\Exception\Http\NotFound
exception for404
errors instead of just sending a header. - Create a default route to catch this exception, ensuring current behaviour is not affected.
Original issue content
I have a question about how to implement a error route for a Default 404 Not Found Page, but have not found the solution.
I created a class Error404 controller to display a standard html page, but it did not work:
$router->any('/**', 'Routes\Error404');
I also tried to use the method errorRoute, but without success.
$router->errorRoute($callback);
Is there a solution to this problem?
Thank's all to help me!
I have suffered from the same problem.
Following the issue.
And while I'm resolving as follows:
$r3->run();
if(! isset($r3->request->route)) {
header("Content-type: application/json");
echo json_encode(['error' => '404 not found']);
}
I'm not the best person to answer about this without spend some time debugging it.
@alganet, can you give us some help?