private static function handler($uri)
    {
        return function (\Exception $e) use ($uri) {
            if ($e instanceof TimeoutException) {
                throw new \RuntimeException(
                    'Connection to ' . $uri . ' timed out after ' . $e->getTimeout() . ' seconds',
                    \defined('SOCKET_ETIMEDOUT') ? \SOCKET_ETIMEDOUT : 0
                );
            }

            throw $e;
        };
    }