Project

General

Profile

Actions

Bug #97666

closed

Extbase ActionController::throwStatus incompatible signature

Added by Adrian Rudnik over 2 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Extbase
Target version:
-
Start date:
2022-05-21
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
11
PHP Version:
8.1
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

While implementing a simple ActionController, I wanted to return a simple 404 status code for a client to consume.

Reduced version of the controller:

<?php

use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;

class ExampleController extends ActionController
{
    public function indexAction(): ResponseInterface
    {
        $all = [];

        if (empty($all)) {
            $this->throwStatus(404);
        }

        return $this->htmlResponse();
    }
}

The call fails because throwStatus($statusCode, $statusMessage = null, $content = null) calls ResponseFactory::createResponse(int $code = 200, string $reasonPhrase = '')

This fails as the allowed NULL of $statusMessage is not allowed by createResponse.

If I expand the call to

$this->throwStatus(404, '');

I get another error, from TypoScriptRenderingMiddleware.php:76 with an error of PHP Warning: Undefined array key 0 in, something related to an empty Content-Type arary within the request headers. But that part could be related to a misconfiguration from my side.

A simple workaround for now is just to use

return new HtmlResponse('', 404);

but I'm not sure if that fits all contexts, and I expected throwStatus to work in any case.


Related issues 2 (0 open2 closed)

Related to TYPO3 Core - Bug #94131: Extbase throwStatus() does not throw status and continues with other pluginsClosedBenni Mack2021-05-12

Actions
Related to TYPO3 Core - Bug #98417: Extbase with empty htmlResponse incompatible signature Closed2022-09-22

Actions
Actions #1

Updated by Oliver Bartsch over 2 years ago

  • Status changed from New to Accepted

Related TypeError

(1/1) TypeError
TYPO3\CMS\Core\Http\ResponseFactory::createResponse(): Argument #2 ($reasonPhrase) must be of type string, null given, called in /var/www/html/typo3/sysext/extbase/Classes/Mvc/Controller/ActionController.php on line 845
Actions #2

Updated by Oliver Bartsch over 2 years ago

  • Related to Bug #94131: Extbase throwStatus() does not throw status and continues with other plugins added
Actions #3

Updated by Gerrit Code Review over 2 years ago

  • Status changed from Accepted to Under Review

Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/74735

Actions #4

Updated by Gerrit Code Review over 2 years ago

Patch set 1 for branch 11.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/74756

Actions #5

Updated by Oliver Bartsch over 2 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #6

Updated by Michael Voehringer about 2 years ago

  • Related to Bug #98417: Extbase with empty htmlResponse incompatible signature added
Actions #7

Updated by Benni Mack about 2 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF