Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make 404 a exception instead of a response #115

Open
2 tasks
edgardcunha opened this issue Feb 23, 2015 · 5 comments
Open
2 tasks

Make 404 a exception instead of a response #115

edgardcunha opened this issue Feb 23, 2015 · 5 comments
Labels
Milestone

Comments

@edgardcunha
Copy link

edgardcunha commented Feb 23, 2015

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!

@brenodouglas
Copy link

I have suffered from the same problem.

Following the issue.

@brenodouglas
Copy link

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']);
}

@henriquemoody
Copy link
Member

I'm not the best person to answer about this without spend some time debugging it.

@alganet, can you give us some help?

@HwapX
Copy link

HwapX commented Jun 9, 2015

@alganet please, can you help us?

@alganet alganet self-assigned this Jun 9, 2015
@augustohp augustohp added the bug label May 13, 2016
@augustohp augustohp added this to the 1.0 milestone May 13, 2016
@augustohp augustohp changed the title Default error route 404 Not Found Make 404 a exception instead of responses May 13, 2016
@augustohp augustohp changed the title Make 404 a exception instead of responses Make 404 a exception instead of a response May 13, 2016
@augustohp
Copy link
Member

I've updated the issue description (keeping the original post under it) with a proposal which I think can handle this and #109 well. This solution is specially motivated by #109.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants