# WARNING: Do not edit by hand, this file was generated by Crank:
#
#   https://github.com/gocardless/crank
#

class GoCardlessProError(Exception):
    """Base exception class for gocardless_pro errors."""


class ApiError(GoCardlessProError):
    """Base exception class for GoCardless API errors. API errors will result
    in one of this class' subclasses being raised.
    """

    def __init__(self, error):
        self.error = error

    @property
    def type(self):
        return self.error['type']

    @property
    def code(self):
        return self.error['code']

    @property
    def errors(self):
        return self.error['errors']

    @property
    def documentation_url(self):
        return self.error['documentation_url']

    @property
    def message(self):
        return self.error['message']

    @property
    def request_id(self):
        return self.error['request_id']

    @classmethod
    def exception_for(cls, error_type):
        if error_type == 'validation_failed':
            return ValidationFailedError
        if error_type == 'invalid_api_usage':
            return InvalidApiUsageError
        if error_type == 'invalid_state':
            return InvalidStateError
        if error_type == 'gocardless':
            return GoCardlessInternalError
        raise GoCardlessProError('Invalid error type "{}"'.format(error_type))


class ValidationFailedError(ApiError):
    pass


class InvalidApiUsageError(ApiError):
    pass


class InvalidStateError(ApiError):
    pass


class GoCardlessInternalError(ApiError):
    pass


class MalformedResponseError(GoCardlessProError):

    def __init__(self, message, response):
        super(MalformedResponseError, self).__init__(message)
        self.response = response


