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';
| improve this answer | |
  • I will check and let u know. Thanks for the response. – gajjala sandeep Jan 4 '19 at 7:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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