@classmethod
def _extract_error_message(cls, response):
    """Extracts an error message from an error response.

        If the server has sent a JSON response with an 'error' field, which is the typical
        behavior of the Realtime Database REST API, parses the response to retrieve the error
        message. If the server has sent a non-JSON response, returns the full response
        as the error message.
        """
    message = None
    try:
        data = response.json()
        if isinstance(data, dict):
            message = data.get('error')
    except ValueError:
        pass
    if not message:
        message = 'Unexpected response from database: {0}'.format(response.
            content.decode())
    return message
