mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 06:04:21 +01:00
First commands with basic structure.
- Moves DBManager to common.
This commit is contained in:
37
watchtower-plugin/exceptions.py
Normal file
37
watchtower-plugin/exceptions.py
Normal file
@@ -0,0 +1,37 @@
|
||||
class BasicException(Exception):
|
||||
def __init__(self, msg, **kwargs):
|
||||
self.msg = msg
|
||||
self.kwargs = kwargs
|
||||
|
||||
def __str__(self):
|
||||
if len(self.kwargs) > 2:
|
||||
params = "".join("{}={}, ".format(k, v) for k, v in self.kwargs.items())
|
||||
|
||||
# Remove the extra 2 characters (space and comma) and add all data to the final message.
|
||||
message = self.msg + " ({})".format(params[:-2])
|
||||
|
||||
else:
|
||||
message = self.msg
|
||||
|
||||
return message
|
||||
|
||||
def to_json(self):
|
||||
response = {"error": self.msg}
|
||||
response.update(self.kwargs)
|
||||
return response
|
||||
|
||||
|
||||
class InvalidParameter(BasicException):
|
||||
"""Raised when a command line parameter is invalid (either missing or wrong)"""
|
||||
|
||||
|
||||
class InvalidKey(BasicException):
|
||||
"""Raised when there is an error loading the keys"""
|
||||
|
||||
|
||||
class TowerConnectionError(BasicException):
|
||||
"""Raised when the tower responds with an error"""
|
||||
|
||||
|
||||
class TowerResponseError(BasicException):
|
||||
"""Raised when the tower responds with an error"""
|
||||
Reference in New Issue
Block a user