Errors, bedrock whitelist bug
This commit is contained in:
parent
7f77478164
commit
c4c5c831c6
5 changed files with 55 additions and 70 deletions
|
@ -21,10 +21,7 @@ from .aterrors import CloudflareError
|
|||
from .aterrors import CredentialsError
|
||||
from .aterrors import TokenError
|
||||
from .aterrors import ServerError
|
||||
from .aterrors import ServerEulaError
|
||||
from .aterrors import ServerRunningError
|
||||
from .aterrors import ServerSoftwareError
|
||||
from .aterrors import ServerStorageError
|
||||
from .aterrors import ServerStartError
|
||||
from .aterrors import FileError
|
||||
from .aterrors import PermissionError
|
||||
from .atjsparse import exec, atob
|
||||
|
@ -41,8 +38,8 @@ __all__ = [
|
|||
'PlayersList', 'AternosConfig', 'AternosWss',
|
||||
'FileManager', 'AternosFile', 'AternosError',
|
||||
'CloudflareError', 'CredentialsError', 'TokenError',
|
||||
'ServerError', 'ServerEulaError', 'ServerRunningError',
|
||||
'ServerSoftwareError', 'ServerStorageError', 'FileError',
|
||||
'ServerError', 'ServerStartError', 'FileError',
|
||||
'PermissionError',
|
||||
'exec', 'atob', 'to_ecma5_function',
|
||||
|
||||
'Edition', 'Status', 'Lists',
|
||||
|
|
|
@ -249,4 +249,6 @@ class AternosConnect:
|
|||
f'{method} completed with {req.status_code} status'
|
||||
)
|
||||
|
||||
req.raise_for_status()
|
||||
|
||||
return req
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
from typing import Final
|
||||
|
||||
|
||||
class AternosError(Exception):
|
||||
|
||||
"""Common error class"""
|
||||
|
@ -23,31 +26,53 @@ class TokenError(AternosError):
|
|||
|
||||
class ServerError(AternosError):
|
||||
|
||||
"""Common class for server errors"""
|
||||
"""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
|
||||
"""
|
||||
|
||||
def __init__(self, reason: str, message: str = '') -> None:
|
||||
|
||||
self.reason = reason
|
||||
super().__init__(message)
|
||||
|
||||
|
||||
class ServerEulaError(ServerError):
|
||||
class ServerStartError(AternosError):
|
||||
|
||||
"""Raised when trying to start without
|
||||
confirming Mojang EULA"""
|
||||
"""Raised when Aternos can not start Minecraft server
|
||||
|
||||
:param reason: Code which contains error reason
|
||||
:type reason: str
|
||||
"""
|
||||
|
||||
class ServerRunningError(ServerError):
|
||||
MESSAGE: Final = 'Unable to start server, code: {}'
|
||||
reason_msg = {
|
||||
|
||||
"""Raised when trying to start
|
||||
already running server"""
|
||||
'eula':
|
||||
'EULA was not accepted. '
|
||||
'Use start(accepteula=True)',
|
||||
|
||||
'already': 'Server is already running',
|
||||
'wrongversion': 'Incorrect software version installed',
|
||||
|
||||
class ServerSoftwareError(ServerError):
|
||||
'file':
|
||||
'File server is unavailbale, '
|
||||
'view https://status.aternos.gmbh',
|
||||
|
||||
"""Raised when Aternos notifies about
|
||||
incorrect software version"""
|
||||
'size': 'Available storage size limit (4 GB) was reached'
|
||||
}
|
||||
|
||||
def __init__(self, reason: str) -> None:
|
||||
|
||||
class ServerStorageError(ServerError):
|
||||
|
||||
"""Raised when Aternos notifies about
|
||||
violation of storage limits (4 GB for now)"""
|
||||
super().__init__(
|
||||
reason,
|
||||
self.reason_msg.get(
|
||||
reason, self.MESSAGE.format(reason)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class FileError(AternosError):
|
||||
|
@ -57,5 +82,6 @@ class FileError(AternosError):
|
|||
|
||||
|
||||
class PermissionError(AternosError):
|
||||
"""Raised when trying to execute a non-allowed
|
||||
command on a server (Think friends permissions)"""
|
||||
|
||||
"""Raised when trying to execute a disallowed command,
|
||||
usually because of shared access rights"""
|
||||
|
|
|
@ -4,11 +4,7 @@ from requests import Response
|
|||
from typing import Optional, List
|
||||
|
||||
from .atconnect import AternosConnect
|
||||
from .aterrors import ServerError
|
||||
from .aterrors import ServerEulaError
|
||||
from .aterrors import ServerRunningError
|
||||
from .aterrors import ServerSoftwareError
|
||||
from .aterrors import ServerStorageError
|
||||
from .aterrors import ServerStartError
|
||||
from .atfm import FileManager
|
||||
from .atconf import AternosConfig
|
||||
from .atplayers import PlayersList
|
||||
|
@ -99,16 +95,8 @@ class AternosServer:
|
|||
:param accepteula: Automatically accept
|
||||
the Mojang EULA, defaults to `True`
|
||||
:type accepteula: bool, optional
|
||||
:raises ServerEulaError: When trying to start a server
|
||||
without accepting the Mojang EULA
|
||||
:raises ServerRunningError: When trying to start a server
|
||||
which is alreday running
|
||||
:raises ServerSoftwareError: When Aternos notifies about
|
||||
incorrect software version
|
||||
:raises ServerStorageError: When Aternos notifies about
|
||||
voilation of storage limits (4 GB for now)
|
||||
:raises ServerError: When API is unable to start a Minecraft server
|
||||
due to unavailability of Aternos' file servers or other problems
|
||||
:raises ServerStartError: When Aternos
|
||||
is unable to start the server
|
||||
"""
|
||||
|
||||
startreq = self.atserver_request(
|
||||
|
@ -120,42 +108,14 @@ class AternosServer:
|
|||
|
||||
if startresult['success']:
|
||||
return
|
||||
|
||||
error = startresult['error']
|
||||
|
||||
if error == 'eula' and accepteula:
|
||||
self.eula()
|
||||
self.start(accepteula=False)
|
||||
return self.start(accepteula=False)
|
||||
|
||||
elif error == 'eula':
|
||||
raise ServerEulaError(
|
||||
'EULA was not accepted. Use start(accepteula=True)'
|
||||
)
|
||||
|
||||
elif error == 'already':
|
||||
raise ServerRunningError(
|
||||
'Server is already running'
|
||||
)
|
||||
|
||||
elif error == 'wrongversion':
|
||||
raise ServerSoftwareError(
|
||||
'Incorrect software version installed'
|
||||
)
|
||||
|
||||
elif error == 'file':
|
||||
raise ServerError(
|
||||
'File server is unavailbale, view https://status.aternos.gmbh'
|
||||
)
|
||||
|
||||
elif error == 'size':
|
||||
raise ServerStorageError(
|
||||
f'Available storage size is 4GB, '
|
||||
f'your server used: {startresult["size"]}'
|
||||
)
|
||||
|
||||
else:
|
||||
raise ServerError(
|
||||
f'Unable to start server, code: {error}'
|
||||
)
|
||||
raise ServerStartError(error)
|
||||
|
||||
def confirm(self) -> None:
|
||||
|
||||
|
|
Reference in a new issue