How to redirect from around plugin to another page with an error ?


Not tested but this might work for you. The ManagerInterface class will set the error message and response class will help in redirecting to specific url.

namespace Vendor\ModuleName\Plugin;

class MyPluginClass
    private $response;

    private $messageManager;

    public function __construct
        \Magento\Framework\Message\ManagerInterface $messageManager,
        \Magento\Framework\App\Response\Http $response
        $this->messageManager = $messageManager;
        $this->response = $response;

    public function aroundSomeMethod($subject, $proceed, $someThingForTrue){
            $this->messageManager->addErrorMessage(__('There seems to be some error'));
            $url = 'http://mystoreurl.com';
  • I will check and let u know. Thanks for the response. – gajjala sandeep Jan 4 at 7:15

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.