protected function generateResponse($statusCode, $json)
    {
        if (empty($json) && $statusCode == Response::REST_SUCCESS_NO_CONTENT) {
            return new Response(array(), $statusCode);
        } else {
            $body = json_decode($json, true);
            if ($body == null) {
                throw new ClientException('Error while sending request to api; Received invalid json: ' . $json, ClientException::SERVER_UNAVAILABLE);
            }
            $response = new Response($body, $statusCode);
            $this->validateServerResponse($response);

            return $response;
        }
    }