protected function validateServerResponse(Response $response)
    {
        switch ($response->getStatusCode()) {
            case Response::REST_CLIENT_ERROR_UNAUTHORIZED:
                throw new ClientException('You have provided an invalid API key', ClientException::INVALID_APPLICATION_SECRET, $response);
                break;
            case Response::REST_CLIENT_ERROR_FORBIDDEN:
                throw new ClientException('Your account is not enabled for the service', ClientException::INVALID_APPLICATION_SECRET, $response);
                break;
            case Response::REST_CLIENT_ERROR_NOT_FOUND:
                throw new ClientException('The requested entity was not found on the server', ClientException::ENTITY_NOT_FOUND, $response);
                break;
            case Response::REST_CLIENT_ERROR_CONFLICT:
                $body = $response->getBody();

                $message = (isset($body['detail'])) ? $body['detail'] : 'The request was rejected due to an conflict.';
                throw new ClientException($message, ClientException::INVALID_RESPONSE, $response);
                break;
            case Response::REST_CLIENT_ERROR_UNPROCESSABLE_ENTITY:
                $body = $response->getBody();

                $message = (isset($body['detail'])) ? $body['detail'] : 'Unable to process the request';
                throw new ClientException($message, ClientException::INVALID_RESPONSE, $response);
                break;
            case Response::REST_CLIENT_ERROR_LOCKED:
                $body = $response->getBody();

                $message = (isset($body['detail'])) ? $body['detail'] : 'The request could not be processed as the entity was locked.';
                throw new ClientException($message, ClientException::INVALID_RESPONSE, $response);
                break;
            case Response::REST_CLIENT_ERROR_TOO_MANY_REQUESTS:
                throw new ClientException('You are sending too fast and your calls are throttled', ClientException::SERVER_UNAVAILABLE, $response);
                break;
            case Response::REST_CLIENT_ERROR_PAYMENT_REQUIRED:
                throw new ClientException('Insufficient credit for your wallet', ClientException::INSUFFICIENT_CREDIT, $response);
                break;
            case Response::REST_SUCCESS_OK:
            case Response::REST_SUCCESS_CREATED:
                break; // Valid response
            default:
                throw new ClientException(sprintf('Unknown status code %d received from server', $response->getStatusCode()), ClientException::INVALID_RESPONSE, $response);
                break;
        }
    }