""" Defines Exception subclasses for errors raised by the survey123-python-api. """


class SurveyError(Exception):
    """
    Abstract base class for exceptions thrown by the Survey123-python-api
    """

    def __init__(self, message):
        """
        :param message: A human readable message describing the error.
        """

        super().__init__(self)
        self.message = message

    def __str__(self):
        return self.message


class ServerError(SurveyError):
    """
    An error that was generated by a service in the backend, such as a portal, feature service, or API.
    """

    def __init__(self, error):
        """:param error: An error string returned by the server."""
        message = "An error occurred while generating reports. Details: {}".format(
            error
        )
        super().__init__(message)
        self.errors = error

    def __repr__(self):
        return "ServerError({})".format(repr(self.errors))
