Respect / Respect/Rest

Make 404 a exception instead of a response

Open
#115 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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\NotFound exception for 404 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!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.