Skip to content
This repository has been archived by the owner on Feb 10, 2023. It is now read-only.

404 handling #30

Open
WanWizard opened this issue Apr 18, 2017 · 8 comments
Open

404 handling #30

WanWizard opened this issue Apr 18, 2017 · 8 comments
Milestone

Comments

@WanWizard
Copy link

Dedicated 404 route plus internal 404 handling if the special route is not defined. Dedicated 404 exception?

@WanWizard
Copy link
Author

@stevewest This can also be handled as part of the decoupling, as the response status is related to response rendering.

@emlynwest
Copy link
Contributor

Ok, sounds like I need to get on with that task then 😉

@emlynwest emlynwest added this to the 2.0.0-beta1 milestone Apr 18, 2017
@sagikazarmark
Copy link

Dedicated HTTP exception? 403 also sounds like a valid target for a custom page. BTW do we need an actual route for this? Isn't a special template enough? #simplicity

This could go into an error controller/listener:
If there is an error404.template use it
(If there is an error4xx.template use it)
If there is an error.template use it

User can override the builtin error controller/listener

@emlynwest
Copy link
Contributor

Sounds good to me, I'm all for simple.

@WanWizard
Copy link
Author

The problem with an exception is that you are pulled out the the normal execution flow. This has in v1 also read to a problematic solution in the index.php with the result that you lose all context of the original request.

@sagikazarmark your suggestion suggests a (fixed) HTML response, which I don't think is a good idea.

If we go for exceptions, I think we need to capture them all (= "system exceptions") at the point the controller is invoked, so we can replace the Response from the controller by a new Response related to the exception captured. That response can than be injected into the normal flow, and rendered bsaed on the required response format (which could be something else than HTML).

@sagikazarmark
Copy link

@sagikazarmark your suggestion suggests a (fixed) HTML response, which I don't think is a good idea.

Care to elaborate? Because in the following paragraph you basically explained how I also imagined error handling to work under the hood and I don't see a contradiction. My point was that for the user it might be enough (on high level) to just put some HTML in a template (following the above fallback chain: 404->4xx->error) and we handle the rest. Of course the user should be able to hook into this logic (which renders the error response), but in most of the cases it sounds just enough to me.

I remember that we imagined some kind of pipeline for the request-response logic (I may still have some drawings on Google Docs). I guess this pipeline would be our "execution flow". If an exception is thrown, an outer middleware of the pipeline (which is responsible for error handling) can catch that exception and continue the execution of the rest of the pipeline.

@WanWizard
Copy link
Author

Ok, I may have misunderstood you. I was under the impression that on a 404 exception, you always wanted to output the HTML. Which of course goes horribly wrong if the Controller is part of a REST API and the caller always expects a JSON response.

@emlynwest
Copy link
Contributor

My thinking was that a 404 exception being thrown and not caught by the developer's application would then simply trigger the normal 404 handling, the result getting returned however has been defined by config or w/e.

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

No branches or pull requests

3 participants