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

Plugin ErrorController not called when inside prefix routing #17025

Closed
ishanvyas22 opened this issue Feb 21, 2023 · 1 comment
Closed

Plugin ErrorController not called when inside prefix routing #17025

ishanvyas22 opened this issue Feb 21, 2023 · 1 comment

Comments

@ishanvyas22
Copy link
Contributor

ishanvyas22 commented Feb 21, 2023

Description

Current behavior

We want to render specific template when error is thrown from the plugin. For that we have ErrorController inside main plugin namespace(let's call it Company\Plugin\Controller), so it would be Company\Plugin1\Controller\ErrorController.

Now when we throw exception from prefix route's controller i.e. Company\Plugin\Controller\Prefix1\FooController or Company\Plugin\Controller\Prefix2\BarController, it doesn't take plugin's Company\Plugin1\Controller\ErrorController into account. But, it calls core's controller(App\Controller\ErrorController).

Upon digging into ControllerFactory, it tries to find Company\Plugin\Controller\Prefix1\ErrorController.

// inside Cake\Controller\ControllerFactory
public function getControllerClass(ServerRequest $request): ?string
{
    ...

    // here in $namespace: Controller/Prefix1 (or Controller/Prefix2)
    return App::className($pluginPath . $controller, $namespace, 'Controller');
}

Expected behavior

Plugin's ErrorController(Company\Plugin1\Controller\ErrorController in our example) should be called.

CakePHP Version

4.3.11

PHP Version

No response

@markstory
Copy link
Member

There isn't currently support for a controller cascade from routing prefixes to the plugin. We could rework the logic in WebExceptionRenderer to attempt the plugin (without prefix) error controller if the current route information includes a prefix.

Moving to a feature as the behavior you're describing does not currently exist. As a workaround you could add a subclass of your plugin error controller to each routing prefix.

@markstory markstory added this to the 4.5.0 milestone Feb 21, 2023
markstory added a commit that referenced this issue Mar 19, 2023
When within a plugin + prefix routing scope if there isn't an
ErrorController for the plugin + prefix, fallback to just the plugin
before falling back to the application/core error controller.

This allows plugins to provide error handling for all of their routes if
they need it.

Fixes #17025
@ADmad ADmad closed this as completed Mar 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants