Bug #97666
closedExtbase ActionController::throwStatus incompatible signature
100%
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.
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
Updated by Oliver Bartsch over 2 years ago
- Related to Bug #94131: Extbase throwStatus() does not throw status and continues with other plugins added
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
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
Updated by Oliver Bartsch over 2 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 1c0cf77ec13efed4aaed27b252626a3399ab32a0.
Updated by Michael Voehringer about 2 years ago
- Related to Bug #98417: Extbase with empty htmlResponse incompatible signature added