mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 17:20:30 +08:00
very common exceptions
This commit is contained in:
parent
dd52a85cf6
commit
3048fc7923
@ -42,16 +42,13 @@ import setproctitle
|
|||||||
|
|
||||||
from ...logging import get_logger
|
from ...logging import get_logger
|
||||||
|
|
||||||
|
from ...errors import OperationError
|
||||||
|
from ...errors import IsBusyError
|
||||||
|
|
||||||
from ...plugins import BasePlugin
|
from ...plugins import BasePlugin
|
||||||
|
|
||||||
from ...plugins.hid import BaseHid
|
from ...plugins.hid import BaseHid
|
||||||
|
|
||||||
from ...plugins.atx import AtxOperationError
|
|
||||||
from ...plugins.atx import AtxIsBusyError
|
|
||||||
from ...plugins.atx import BaseAtx
|
from ...plugins.atx import BaseAtx
|
||||||
|
|
||||||
from ...plugins.msd import MsdOperationError
|
|
||||||
from ...plugins.msd import MsdIsBusyError
|
|
||||||
from ...plugins.msd import BaseMsd
|
from ...plugins.msd import BaseMsd
|
||||||
|
|
||||||
from ...validators import ValidatorError
|
from ...validators import ValidatorError
|
||||||
@ -71,8 +68,6 @@ from .auth import AuthManager
|
|||||||
from .info import InfoManager
|
from .info import InfoManager
|
||||||
from .logreader import LogReader
|
from .logreader import LogReader
|
||||||
from .streamer import Streamer
|
from .streamer import Streamer
|
||||||
|
|
||||||
from .wol import WolDisabledError
|
|
||||||
from .wol import WakeOnLan
|
from .wol import WakeOnLan
|
||||||
|
|
||||||
from .http import UnauthorizedError
|
from .http import UnauthorizedError
|
||||||
@ -337,9 +332,9 @@ class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-ins
|
|||||||
|
|
||||||
return (await exposed.handler(request))
|
return (await exposed.handler(request))
|
||||||
|
|
||||||
except (AtxIsBusyError, MsdIsBusyError) as err:
|
except IsBusyError as err:
|
||||||
return make_json_exception(err, 409)
|
return make_json_exception(err, 409)
|
||||||
except (ValidatorError, AtxOperationError, MsdOperationError, WolDisabledError) as err:
|
except (ValidatorError, OperationError) as err:
|
||||||
return make_json_exception(err, 400)
|
return make_json_exception(err, 400)
|
||||||
except UnauthorizedError as err:
|
except UnauthorizedError as err:
|
||||||
return make_json_exception(err, 401)
|
return make_json_exception(err, 401)
|
||||||
|
|||||||
@ -27,11 +27,13 @@ from typing import Optional
|
|||||||
|
|
||||||
from ...logging import get_logger
|
from ...logging import get_logger
|
||||||
|
|
||||||
|
from ...errors import OperationError
|
||||||
|
|
||||||
from ... import aiotools
|
from ... import aiotools
|
||||||
|
|
||||||
|
|
||||||
# =====
|
# =====
|
||||||
class WolDisabledError(Exception):
|
class WolDisabledError(OperationError):
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__("WoL is disabled")
|
super().__init__("WoL is disabled")
|
||||||
|
|
||||||
|
|||||||
28
kvmd/errors.py
Normal file
28
kvmd/errors.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# ========================================================================== #
|
||||||
|
# #
|
||||||
|
# KVMD - The main Pi-KVM daemon. #
|
||||||
|
# #
|
||||||
|
# Copyright (C) 2018 Maxim Devaev <mdevaev@gmail.com> #
|
||||||
|
# #
|
||||||
|
# This program is free software: you can redistribute it and/or modify #
|
||||||
|
# it under the terms of the GNU General Public License as published by #
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or #
|
||||||
|
# (at your option) any later version. #
|
||||||
|
# #
|
||||||
|
# This program is distributed in the hope that it will be useful, #
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||||
|
# GNU General Public License for more details. #
|
||||||
|
# #
|
||||||
|
# You should have received a copy of the GNU General Public License #
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
|
||||||
|
# #
|
||||||
|
# ========================================================================== #
|
||||||
|
|
||||||
|
|
||||||
|
class OperationError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class IsBusyError(Exception):
|
||||||
|
pass
|
||||||
@ -24,6 +24,9 @@ from typing import Dict
|
|||||||
from typing import AsyncGenerator
|
from typing import AsyncGenerator
|
||||||
from typing import Type
|
from typing import Type
|
||||||
|
|
||||||
|
from ...errors import OperationError
|
||||||
|
from ...errors import IsBusyError
|
||||||
|
|
||||||
from .. import BasePlugin
|
from .. import BasePlugin
|
||||||
from .. import get_plugin_class
|
from .. import get_plugin_class
|
||||||
|
|
||||||
@ -33,11 +36,11 @@ class AtxError(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class AtxOperationError(AtxError):
|
class AtxOperationError(OperationError, AtxError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class AtxIsBusyError(AtxOperationError):
|
class AtxIsBusyError(IsBusyError, AtxError):
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__("Performing another ATX operation, please try again later")
|
super().__init__("Performing another ATX operation, please try again later")
|
||||||
|
|
||||||
|
|||||||
@ -27,6 +27,9 @@ from typing import Type
|
|||||||
from typing import AsyncGenerator
|
from typing import AsyncGenerator
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
from ...errors import OperationError
|
||||||
|
from ...errors import IsBusyError
|
||||||
|
|
||||||
from .. import BasePlugin
|
from .. import BasePlugin
|
||||||
from .. import get_plugin_class
|
from .. import get_plugin_class
|
||||||
|
|
||||||
@ -36,10 +39,15 @@ class MsdError(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class MsdOperationError(MsdError):
|
class MsdOperationError(OperationError, MsdError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class MsdIsBusyError(IsBusyError, MsdError):
|
||||||
|
def __init__(self) -> None:
|
||||||
|
super().__init__("Performing another MSD operation, please try again later")
|
||||||
|
|
||||||
|
|
||||||
class MsdOfflineError(MsdOperationError):
|
class MsdOfflineError(MsdOperationError):
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__("MSD is not found")
|
super().__init__("MSD is not found")
|
||||||
@ -70,11 +78,6 @@ class MsdImageExistsError(MsdOperationError):
|
|||||||
super().__init__("This image is already exists")
|
super().__init__("This image is already exists")
|
||||||
|
|
||||||
|
|
||||||
class MsdIsBusyError(MsdOperationError):
|
|
||||||
def __init__(self) -> None:
|
|
||||||
super().__init__("Performing another MSD operation, please try again later")
|
|
||||||
|
|
||||||
|
|
||||||
class MsdMultiNotSupported(MsdOperationError):
|
class MsdMultiNotSupported(MsdOperationError):
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__("This MSD does not support storing multiple images")
|
super().__init__("This MSD does not support storing multiple images")
|
||||||
|
|||||||
@ -48,13 +48,13 @@ from .... import aiotools
|
|||||||
from .... import aioregion
|
from .... import aioregion
|
||||||
|
|
||||||
from .. import MsdError
|
from .. import MsdError
|
||||||
|
from .. import MsdIsBusyError
|
||||||
from .. import MsdOfflineError
|
from .. import MsdOfflineError
|
||||||
from .. import MsdConnectedError
|
from .. import MsdConnectedError
|
||||||
from .. import MsdDisconnectedError
|
from .. import MsdDisconnectedError
|
||||||
from .. import MsdImageNotSelected
|
from .. import MsdImageNotSelected
|
||||||
from .. import MsdUnknownImageError
|
from .. import MsdUnknownImageError
|
||||||
from .. import MsdImageExistsError
|
from .. import MsdImageExistsError
|
||||||
from .. import MsdIsBusyError
|
|
||||||
from .. import BaseMsd
|
from .. import BaseMsd
|
||||||
|
|
||||||
from . import fs
|
from . import fs
|
||||||
|
|||||||
@ -53,10 +53,10 @@ from ...validators.os import valid_abs_path
|
|||||||
from ...validators.hw import valid_gpio_pin
|
from ...validators.hw import valid_gpio_pin
|
||||||
|
|
||||||
from . import MsdError
|
from . import MsdError
|
||||||
|
from . import MsdIsBusyError
|
||||||
from . import MsdOfflineError
|
from . import MsdOfflineError
|
||||||
from . import MsdConnectedError
|
from . import MsdConnectedError
|
||||||
from . import MsdDisconnectedError
|
from . import MsdDisconnectedError
|
||||||
from . import MsdIsBusyError
|
|
||||||
from . import MsdMultiNotSupported
|
from . import MsdMultiNotSupported
|
||||||
from . import MsdCdromNotSupported
|
from . import MsdCdromNotSupported
|
||||||
from . import BaseMsd
|
from . import BaseMsd
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user