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
Laptop 5971837cbf
Fix aterrors.py
Fix mistake on line 1
2022-09-20 20:09:21 +03:00

97 lines
2.2 KiB
Python

"""Exception classes"""
from typing import Final
class AternosError(Exception):
"""Common error class"""
class CloudflareError(AternosError):
"""Raised when the parser is unable
to bypass Cloudflare protection"""
class CredentialsError(AternosError):
"""Raised when a session cookie is empty
which means incorrect credentials"""
class TokenError(AternosError):
"""Raised when the parser is unable
to extract Aternos ajax token"""
class ServerError(AternosError):
"""Common class for server errors"""
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
"""
self.reason = reason
super().__init__(message)
class ServerStartError(AternosError):
"""Raised when Aternos can not start Minecraft server"""
MESSAGE: Final = 'Unable to start server, code: {}'
reason_msg = {
'eula':
'EULA was not accepted. '
'Use start(accepteula=True)',
'already': 'Server has already started',
'wrongversion': 'Incorrect software version installed',
'file':
'File server is unavailbale, '
'view https://status.aternos.gmbh',
'size': 'Available storage size limit (4 GB) has been reached'
}
def __init__(self, reason: str) -> None:
"""Raised when Aternos
can not start Minecraft server
Args:
reason (str):
Code which contains error reason
"""
super().__init__(
reason,
self.reason_msg.get(
reason,
self.MESSAGE.format(reason)
)
)
class FileError(AternosError):
"""Raised when trying to execute a disallowed
by Aternos file operation"""
# PermissionError is a built-in,
# so this exception called AternosPermissionError
class AternosPermissionError(AternosError):
"""Raised when trying to execute a disallowed command,
usually because of shared access rights"""