private static function createException(RequestInterface $request,
        ResponseInterface $altered,
        \Exception $previous = null,
        array $ctx = []
    ) {
        if ($altered->getStatusCode() >= 400 && $altered->getStatusCode() < 500) {
            return new ClientException($request, $altered, $previous, $ctx);
        }

        return new ServerException($request, $altered, $previous, $ctx);
    }