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.