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

[Issue] Fix exception handling inconsistency between developer and production modes #38639

Open
5 tasks
m2-assistant bot opened this issue Apr 19, 2024 · 2 comments · May be fixed by #37712
Open
5 tasks

[Issue] Fix exception handling inconsistency between developer and production modes #38639

m2-assistant bot opened this issue Apr 19, 2024 · 2 comments · May be fixed by #37712
Assignees
Labels
Area: Framework Component: Framework/Exception Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: PR Created Indicates that Pull Request has been created to fix issue Progress: PR in progress Reported on 2.4.x Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch

Comments

@m2-assistant
Copy link

m2-assistant bot commented Apr 19, 2024

This issue is automatically created based on existing pull request: #37712: Fix exception handling inconsistency between developer and production modes


Description (*)

During developing our custom module was found an issue in the developer mode, for example, after implementing \Magento\Customer\Controller\AccountInterface class into the custom controller we got redirected to the login page (as was expected), but on the production on the same flow we got an internal server error 500.
It happened because the redirect URL was set to the response before the trigger exception and as a result Location header was sent to the browser and the browser redirect to the login page instead of the page with an exception message.
It's not expected flow between developer and production modes and can cause some issues for production.

Preconditions and environment

  • Magento 2.4.5
  • Controller, which sets a redirect and throws an exception

Steps to reproduce

  1. Create a module:

app/code/Vendor/Module/registration.php:

<?php

use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Vendor_Module', __DIR__);

app/code/Vendor/Module/etc/module.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Vendor_Module"/>
</config>

app/code/Vendor/Module/etc/frontend/routes.xml:

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="standard">
        <route id="vendor" frontName="vendor">
            <module name="Vendor_Module"/>
        </route>
    </router>
</config>

magento2/app/code/Vendor/Module/Controller/Example/Index.php:

<?php

namespace Vendor\Module\Controller\Example;

use LogicException;
use Magento\Customer\Model\Session;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Exception\SessionException;

class Index implements HttpGetActionInterface
{
    public function __construct(private readonly Session $customerSession,)
    {
    }

    /**
     * Execute action based on request and return result
     *
     * @return ResultInterface|ResponseInterface
     * @throws LogicException
     * @throws SessionException
     */
    public function execute()
    {
        // Here, you will be redirected to the login page when not logged in.
        $this->customerSession->authenticate();

        throw new LogicException(__('Some exception text'));
    }
}
  1. Go to www.domain.com/vendor/example

Expected result

  • Page with exception text like this one:

Capture 2023-07-04 at 14 15 49

Actual result

  • Redirect to the login page

Unfortunately, I don't have enough experience with test coverage, will be great if someone covers this case by test.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)
@m2-assistant m2-assistant bot added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Apr 19, 2024
@m2-community-project m2-community-project bot added this to Pull Request In Progress in High Priority Backlog Apr 19, 2024
@engcom-Charlie engcom-Charlie added Reported on 2.4.x Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Area: Framework Component: Framework/Exception Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed labels Apr 19, 2024
@github-jira-sync-bot
Copy link

✅ Jira issue https://jira.corp.adobe.com/browse/AC-11829 is successfully created for this GitHub issue.

Copy link
Author

m2-assistant bot commented Apr 19, 2024

✅ Confirmed by @engcom-Charlie. Thank you for verifying the issue.
Issue Available: @engcom-Charlie, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@github-jira-sync-bot github-jira-sync-bot added the Progress: PR Created Indicates that Pull Request has been created to fix issue label Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Framework Component: Framework/Exception Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: PR Created Indicates that Pull Request has been created to fix issue Progress: PR in progress Reported on 2.4.x Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch
Projects
High Priority Backlog
  
Pull Request In Progress
Development

Successfully merging a pull request may close this issue.

3 participants