New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add HTTP 111: Connection Refused #1947
Conversation
@skyzyx: How can I reproduce this? I don't get the exception about a missing reason code that you report in my testing. Using this code: $app->get('/', function ($request, $response) {
$client = new Predis\Client();
$client->set('foo', 'bar');
$value = $client->get('foo');
$response->write("Value = $value");
return $response;
}); I get either: I see in your stack trace that you have a |
Let me try to share in pieces. I'm building a JSON-only API, so I've overridden the handlers that default to sending HTML back. bootstrap.php: ...
$config['errorHandler'] = new Application\EventHandler\Error\ErrorHandler($config);
... Application/EventHandler/Error/ErrorHandler.php: namespace Application\EventHandler\Error;
use Application\Dictionary\Http as HttpDict;
use Application\Util\Url;
use Throwable;
use GuzzleHttp\Psr7;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Container;
class ErrorHandler extends AbstractHandler
{
public function __invoke(Container $c)
{
/**
* @param \Psr\Http\Message\ServerRequestInterface $request PSR7 request
* @param \Psr\Http\Message\ResponseInterface $response PSR7 response
* @param \Throwable $exception The exception thrown.
*
* @return \Psr\Http\Message\ResponseInterface
*/
return function (Request $request, Response $response, Throwable $exception) use ($c)
{
$error_code = $exception->getCode() ?: 500;
$error = HttpDict::getStatus($error_code);
$error['message'] = $exception->getMessage();
unset($error['standard_message']);
$request_id = $request->getHeaderLine('X-Request-Id');
// Clear the body.
$response = $response->withBody(Psr7\stream_for(''));
$response = $response->withJson([
'error' => [
'errors' => array_merge($error, [
'resource' => Url::getCompleteUrl($request),
]),
'code' => $error_code,
]
], $error_code, $this->config['json_options'])
->withAddedHeader('X-Request-Id', $request_id);
$this->logRequest($request);
$this->logResponse($response);
return $response;
};
}
} In short, it happens when
|
You should not set Redis' error code as an HTTP status code as it isn't one. You should set the response to a valid HTTP status code in the 5xx series and log the Redis code for your own diagnostics. |
Nginx, Memcache, MySQL, cURL, and lots of other software return this code when a connection has been refused. But I cannot find a canonical source of information which suggests that this is an HTTP code, so I'll let this go. Perhaps it's simply an error code that all major web software implements. sigh Thanks for taking a look at this. |
Ran into this when attempting to connect to a turned-off Redis server using the Predis library through Slim. This was the HTTP error code that was returned, and Slim triggered the
phpErrorHandler
against its own code because this was missing from the list.I had never heard of this error code before, and I could not find it in RFC 2616 or RFC 6585. But apparently it's quite common. Google: http error 111.
Here is the Exception that was logged. Cleaned-up for readability.
Running on PHP 7.0.9. Slim Framework 3.5.0. Here is a snippet from
composer.lock
: