Description
So let me explain - if a user tries to access an unknown URL, our router will throw a MissingRouteException which will get caught by the ErrorHandlerMiddleware.
This of course causes the fact, that any middleware after the RoutingMiddleware has never been called and therefore e.g. no authentication data is present for these kind of URLs as our generic error controller and template will just show the error which has been thrown.
One could try to move the RoutingMiddleware after all the other middlewares, but then we have the problem that our array based routing system won't work up until this point as the Router hasn't been built yet.
I think this can be improved in that way, that we try-catch certain known exceptions in our RoutingMiddleware and in such a MissingRouteException - same as we do in the WebExceptionRenderer - we build our own request params to call the ErrorController with - this time - a real controller action error400().
With that all the other middleware calls are still being made and all the necessary data is present + the user has a bit more control over what is being passed down to the error400.php template which is already present in each app template for quite some time.
My goal here is the fact, that we should split up known exceptions from our side from the ErrorHandlerMiddleware as its primary purpose is to handle other exceptions (like RedirectExceptions or other not catched generic or exceptions)
Thoughts? 😁
CakePHP Version
6.0
Description
So let me explain - if a user tries to access an unknown URL, our router will throw a
MissingRouteExceptionwhich will get caught by the ErrorHandlerMiddleware.This of course causes the fact, that any middleware after the RoutingMiddleware has never been called and therefore e.g. no authentication data is present for these kind of URLs as our generic error controller and template will just show the error which has been thrown.
One could try to move the RoutingMiddleware after all the other middlewares, but then we have the problem that our array based routing system won't work up until this point as the Router hasn't been built yet.
I think this can be improved in that way, that we try-catch certain known exceptions in our RoutingMiddleware and in such a
MissingRouteException- same as we do in the WebExceptionRenderer - we build our own request params to call the ErrorController with - this time - a real controller actionerror400().With that all the other middleware calls are still being made and all the necessary data is present + the user has a bit more control over what is being passed down to the
error400.phptemplate which is already present in each app template for quite some time.My goal here is the fact, that we should split up known exceptions from our side from the ErrorHandlerMiddleware as its primary purpose is to handle other exceptions (like RedirectExceptions or other not catched generic or exceptions)
Thoughts? 😁
CakePHP Version
6.0