Make 404 a exception instead of a response
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 605
- Forks
- 100
- PR merge metrics
- No merged PRs in 30d
Description
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\NotFoundexception for404errors 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!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the exception handling documentation and the existing errorRoute behavior described in the issue. Trace how a 404 currently sends its header, then determine where the NotFound exception and default route belong. Done means 404 errors are catchable by type, can use route routines and content negotiation, and preserve current behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100