Rest icon indicating copy to clipboard operation
Rest copied to clipboard

Make 404 a exception instead of a response

Open edgardcunha opened this issue 10 years ago • 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 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!

edgardcunha avatar Feb 23 '15 12:02 edgardcunha

I have suffered from the same problem.

Following the issue.

brenodouglas avatar Mar 08 '15 18:03 brenodouglas

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

brenodouglas avatar Mar 08 '15 19:03 brenodouglas

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

@alganet, can you give us some help?

henriquemoody avatar Mar 08 '15 20:03 henriquemoody

@alganet please, can you help us?

HwapX avatar Jun 09 '15 18:06 HwapX

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.

augustohp avatar May 13 '16 04:05 augustohp