Get 500 even if I set response code to 440

I got a status code 440 from an API call made on server and would like to relay that code back to front end. I tried with something like


where HTTP_STATUS_LOGIN_TIMEOUT is defined as 440 and the object is an instance of \Laminas\Mvc\Controller\AbstractRestfulController. However, I always get a 500 in HTTP response. There are no exceptions in error logs. I tried with other code such as 444 or 401, it works as expected, what ever code I set is properly returned. Could someone please help?

As an update I can resolve this by adding 440 to vendor/laminas/laminas-http/src/Response.php. Ideally, we can have this file updated in the next release. Or is there a way I can create a PR?

You can create a PR on GitHub. Since 440 is an unofficial HTTP status code, I do not see any chance of success.

Do not edit the vendor package. Never ever do this! Have you tried Laminas\Http\PhpEnvironment\Response::setCustomStatusCode() and Laminas\Http\PhpEnvironment\Response::setReasonPhrase() already?

/** @var \Laminas\Http\PhpEnvironment\Response $response */
$response = $this->getResponse();
$response = $response
    ->setReasonPhrase('Login time-out');

return $response;

Tested it in an own project. Worked fine without an 500 server error.

Thanks a lot! That’s exactly what I’m looking for.