This repository has been archived on 2024-07-30. You can view files and clone it, but cannot push or open issues or pull requests.
python-aternos/python_aternos/aterrors.py

102 lines
2.3 KiB
Python
Raw Permalink Normal View History

2022-09-20 20:09:21 +03:00
"""Exception classes"""
2022-07-01 13:28:39 +03:00
2022-07-01 09:31:23 +03:00
from typing import Final
2021-10-08 18:35:20 +03:00
class AternosError(Exception):
2022-06-16 14:40:10 +03:00
2022-06-23 14:13:56 +03:00
"""Common error class"""
2021-10-08 18:35:20 +03:00
2022-04-28 08:23:02 +03:00
class CloudflareError(AternosError):
2022-06-23 14:13:56 +03:00
"""Raised when the parser is unable
to bypass Cloudflare protection"""
2022-04-28 08:23:02 +03:00
2022-03-18 17:38:36 +03:00
class CredentialsError(AternosError):
2022-06-23 14:13:56 +03:00
"""Raised when a session cookie is empty
which means incorrect credentials"""
2022-06-16 14:40:10 +03:00
2022-09-23 16:21:17 +03:00
class TwoFactorAuthError(CredentialsError):
"""Raised if 2FA is enabled,
but code was not passed to a login function"""
2022-06-16 14:40:10 +03:00
class TokenError(AternosError):
2022-06-23 14:13:56 +03:00
"""Raised when the parser is unable
to extract Aternos ajax token"""
2021-10-08 18:35:20 +03:00
2022-03-18 17:38:36 +03:00
class ServerError(AternosError):
2022-06-23 14:13:56 +03:00
"""Common class for server errors"""
2022-06-23 14:13:56 +03:00
2022-07-01 09:31:23 +03:00
def __init__(self, reason: str, message: str = '') -> None:
"""Common class for server errors
Args:
reason (str): Code which contains error reason
message (str, optional): Error message
"""
2022-07-01 09:31:23 +03:00
self.reason = reason
super().__init__(message)
2022-06-16 14:40:10 +03:00
2022-06-23 14:13:56 +03:00
2022-07-01 09:31:23 +03:00
class ServerStartError(AternosError):
2022-06-16 14:40:10 +03:00
"""Raised when Aternos can not start Minecraft server"""
2022-06-23 14:13:56 +03:00
2022-07-01 09:31:23 +03:00
MESSAGE: Final = 'Unable to start server, code: {}'
reason_msg = {
2022-06-16 14:40:10 +03:00
2022-07-01 09:31:23 +03:00
'eula':
'EULA was not accepted. '
'Use start(accepteula=True)',
2022-06-16 14:40:10 +03:00
'already': 'Server has already started',
2022-07-01 09:31:23 +03:00
'wrongversion': 'Incorrect software version installed',
2022-06-23 14:13:56 +03:00
2022-07-01 09:31:23 +03:00
'file':
'File server is unavailbale, '
'view https://status.aternos.gmbh',
2022-06-16 14:40:10 +03:00
'size': 'Available storage size limit (4 GB) has been reached'
2022-07-01 09:31:23 +03:00
}
2022-06-16 14:40:10 +03:00
2022-07-01 09:31:23 +03:00
def __init__(self, reason: str) -> None:
"""Raised when Aternos
can not start Minecraft server
Args:
reason (str):
Code which contains error reason
"""
2022-07-01 09:31:23 +03:00
super().__init__(
reason,
self.reason_msg.get(
reason,
self.MESSAGE.format(reason)
2022-07-01 09:31:23 +03:00
)
)
2022-06-23 14:13:56 +03:00
2022-03-18 17:38:36 +03:00
class FileError(AternosError):
2022-06-23 14:13:56 +03:00
"""Raised when trying to execute a disallowed
by Aternos file operation"""
2022-07-01 04:47:19 +03:00
2022-07-01 09:31:23 +03:00
2022-07-01 13:28:39 +03:00
# PermissionError is a built-in,
# so this exception called AternosPermissionError
class AternosPermissionError(AternosError):
2022-07-01 09:31:23 +03:00
"""Raised when trying to execute a disallowed command,
usually because of shared access rights"""