2022-01-07 16:45:12 +01:00
|
|
|
class SLException(Exception):
|
|
|
|
def __str__(self):
|
|
|
|
super_str = super().__str__()
|
|
|
|
return f"{type(self).__name__} {super_str}"
|
|
|
|
|
2022-04-21 18:40:24 +02:00
|
|
|
def error_for_user(self) -> str:
|
|
|
|
"""By default send the exception errror to the user. Should be overloaded by the child exceptions"""
|
|
|
|
return str(self)
|
|
|
|
|
2022-01-07 16:45:12 +01:00
|
|
|
|
|
|
|
class AliasInTrashError(SLException):
|
2022-02-06 15:25:53 +01:00
|
|
|
"""raised when alias is deleted before"""
|
2020-05-07 22:28:49 +02:00
|
|
|
|
2020-05-07 22:23:36 +02:00
|
|
|
pass
|
2021-11-17 17:02:31 +01:00
|
|
|
|
|
|
|
|
2022-01-07 16:45:12 +01:00
|
|
|
class DirectoryInTrashError(SLException):
|
2022-02-06 15:25:53 +01:00
|
|
|
"""raised when a directory is deleted before"""
|
2021-11-17 17:02:31 +01:00
|
|
|
|
|
|
|
pass
|
2021-11-17 17:21:13 +01:00
|
|
|
|
|
|
|
|
2022-01-07 16:45:12 +01:00
|
|
|
class SubdomainInTrashError(SLException):
|
2022-02-06 15:25:53 +01:00
|
|
|
"""raised when a subdomain is deleted before"""
|
2021-11-17 17:21:13 +01:00
|
|
|
|
|
|
|
pass
|
2022-01-07 10:04:12 +01:00
|
|
|
|
|
|
|
|
2022-01-07 16:45:12 +01:00
|
|
|
class CannotCreateContactForReverseAlias(SLException):
|
2022-01-07 10:04:12 +01:00
|
|
|
"""raised when a contact is created that has website_email=reverse_alias of another contact"""
|
|
|
|
|
2022-04-21 18:40:24 +02:00
|
|
|
def error_for_user(self) -> str:
|
|
|
|
return "You can't create contact for a reverse alias"
|
2022-01-07 10:34:08 +01:00
|
|
|
|
|
|
|
|
2022-01-07 16:45:12 +01:00
|
|
|
class NonReverseAliasInReplyPhase(SLException):
|
2022-01-07 10:34:08 +01:00
|
|
|
"""raised when a non reverse-alias is used during a reply phase"""
|
|
|
|
|
|
|
|
pass
|
2022-01-07 14:57:47 +01:00
|
|
|
|
|
|
|
|
2022-01-07 16:45:12 +01:00
|
|
|
class VERPTransactional(SLException):
|
2022-01-07 14:57:47 +01:00
|
|
|
"""raised an email sent to a transactional VERP can't be handled"""
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2022-01-07 16:45:12 +01:00
|
|
|
class VERPForward(SLException):
|
2022-01-07 14:57:47 +01:00
|
|
|
"""raised an email sent to a forward VERP can't be handled"""
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2022-01-07 16:45:12 +01:00
|
|
|
class VERPReply(SLException):
|
2022-01-07 14:57:47 +01:00
|
|
|
"""raised an email sent to a reply VERP can't be handled"""
|
|
|
|
|
|
|
|
pass
|
2022-01-07 16:14:21 +01:00
|
|
|
|
|
|
|
|
2022-01-07 16:45:12 +01:00
|
|
|
class MailSentFromReverseAlias(SLException):
|
2022-01-07 16:14:21 +01:00
|
|
|
"""raised when receiving an email sent from a reverse alias"""
|
|
|
|
|
|
|
|
pass
|
2022-05-05 15:05:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ProtonPartnerNotSetUp(SLException):
|
|
|
|
pass
|
2022-04-21 18:40:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ErrContactErrorUpgradeNeeded(SLException):
|
|
|
|
"""raised when user cannot create a contact because the plan doesn't allow it"""
|
|
|
|
|
|
|
|
def error_for_user(self) -> str:
|
2023-03-13 13:01:00 +01:00
|
|
|
return "Please upgrade to premium to create reverse-alias"
|
2022-04-21 18:40:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ErrAddressInvalid(SLException):
|
|
|
|
"""raised when an address is invalid"""
|
|
|
|
|
|
|
|
def __init__(self, address: str):
|
|
|
|
self.address = address
|
|
|
|
|
|
|
|
def error_for_user(self) -> str:
|
|
|
|
return f"{self.address} is not a valid email address"
|
|
|
|
|
|
|
|
|
2023-08-03 10:20:25 +02:00
|
|
|
class InvalidContactEmailError(SLException):
|
|
|
|
def __init__(self, website_email: str): # noqa: F821
|
|
|
|
self.website_email = website_email
|
|
|
|
|
|
|
|
def error_for_user(self) -> str:
|
|
|
|
return f"Cannot create contact with invalid email {self.website_email}"
|
|
|
|
|
|
|
|
|
2022-04-21 18:40:24 +02:00
|
|
|
class ErrContactAlreadyExists(SLException):
|
|
|
|
"""raised when a contact already exists"""
|
|
|
|
|
|
|
|
# TODO: type-hint this as a contact when models are almost dataclasses and don't import errors
|
2022-05-12 18:42:16 +02:00
|
|
|
def __init__(self, contact: "Contact"): # noqa: F821
|
2022-04-21 18:40:24 +02:00
|
|
|
self.contact = contact
|
|
|
|
|
|
|
|
def error_for_user(self) -> str:
|
|
|
|
return f"{self.contact.website_email} is already added"
|
2022-06-09 10:19:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
class LinkException(SLException):
|
|
|
|
def __init__(self, message: str):
|
|
|
|
self.message = message
|
|
|
|
|
|
|
|
|
|
|
|
class AccountAlreadyLinkedToAnotherPartnerException(LinkException):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__("This account is already linked to another partner")
|
|
|
|
|
|
|
|
|
|
|
|
class AccountAlreadyLinkedToAnotherUserException(LinkException):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__("This account is linked to another user")
|
2023-03-13 13:01:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
class AccountIsUsingAliasAsEmail(LinkException):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__("Your account has an alias as it's email address")
|
2023-08-18 15:59:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ProtonAccountNotVerified(LinkException):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__(
|
|
|
|
"The Proton account you are trying to use has not been verified"
|
|
|
|
)
|