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
DarkCat09 4892430f19 MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.

Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00

97 lines
2.2 KiB
Python

"""Exceptions 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"""