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

Also available in: Atom PDF