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

92 lines
2.1 KiB
Python
Raw Normal View History

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