[docs]class BasicException(Exception):
"""Base exception for all the other custom ones. Allows to store a message and some ``kwargs``."""
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
[docs] def to_json(self):
"""Converts the exception to json format."""
response = {"error": self.msg}
response.update(self.kwargs)
return response
[docs]class InvalidParameter(BasicException):
"""Raised when a command line parameter is invalid (either missing or wrong)."""
[docs]class InvalidKey(BasicException):
"""Raised when there is an error loading the keys."""
[docs]class EncryptionError(BasicException):
"""Raised when there is an error with encryption related functions, covers decryption."""
[docs]class SignatureError(BasicException):
"""Raised when there is an with the signature related functions, covers EC recover."""
[docs]class TowerConnectionError(BasicException):
"""Raised when the tower responds with an error."""
[docs]class TowerResponseError(BasicException):
"""Raised when the tower responds with an error."""